connect4

Connect 4 Board Game
Log | Files | Refs

commit f0be7b5d1b4c30b1bc24a93be29a722af1334617
parent 9aaee4de53df1a61d74042639d695bda578b3496
Author: sej <sej@sejdt.localhost>
Date:   Fri,  4 Oct 2024 23:22:31 +0200

Begin Minimax

Diffstat:
AMinimax.cs | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)

diff --git a/Minimax.cs b/Minimax.cs @@ -0,0 +1,54 @@ +using System; + +public class Minimax { + + private class MinimaxTree { + public MinimaxTree( Board rootBoard, int depth ) { + Node root = new Node( rootBoard, depth ); + } + + public int Minimax() { + return 0; + } + + private class Node { + private Board _board; + private List< Node > _children; + + public Node( Board board, int depth ) { + _board = board; + _children = new List< Node >(); + if ( depth > 0 ) { + foreach ( int move in board.LegalMoves() ) { + Board child = new Board( board ); + child.Play( move ); + // child.PrettyPrint(); + _children.Add( new Node( child, depth - 1 ) ); + } + } + } + } + + /* + * Computes a simple heuristic rating for the given board. + * The rating is given by: + * n_2 * w_1 + n_3 * w_2 + w_3 * n_4 + * where n_k is the number of k in a row that has the potential to become 4 in a row (ie. not blocked). + * n_4 obviously has to be infty + * n_2 and n_3 are set to 1, and 2, respectively. + */ + private static int HeuristicScore( Board board ) { + // TODO + return 0; + } + } + + /* + * Returns the best move for the next player's turn on the given board. + */ + public static int NextMove( Board board, int depth ) { + MinimaxTree tree = new MinimaxTree( board, depth ); + int bestMove = tree.Minimax(); + return bestMove; + } +}