minimax_test.cs

来自「tic tac toe is simple game .I think ever」· CS 代码 · 共 97 行

CS
97
字号
/*
using System;
class MiniMaxTest
{
    public static void Main()
    {
        Board board = new Board(3);
        board.MakeMove(1, new Move(1, 2));
        board.MakeMove(1, new Move(0, 2));
        board.MakeMove(1, new Move(1, 0));
        //board.MakeMove(-1, new Move(0, 0));
        board.MakeMove(-1, new Move(2, 0));
        board.MakeMove(-1, new Move(1, 1));




        Move move = GetBestMove(board, -1, 3);
        Console.WriteLine("GetBestMove chose the move ({0}, {1}) ", move.iCol.ToString(), move.iRow.ToString()); 

    }

    public static Move GetBestMove(Board board, int CurrentPlayer, int iBoardSize)
    {


        Move BestMove = null;
        int iPossibleMoves = board.iEmptySquares;

        //Start at a random square, so that if two or more moves
        //are of equal rank, one of them will be chosne at random.
        Random rand = new Random();
        int i = rand.Next(board.iBoardSize - 1);
        int j = rand.Next(board.iBoardSize - 1);

        while (iPossibleMoves > 0)
        {
            //loop through aiBoard to find next available move
            do
            {
                if (i < iBoardSize - 1)
                {
                    i++;
                }
                else if (j < iBoardSize - 1)
                {
                    i = 0; j++;
                }
                else
                {
                    i = 0; j = 0;
                }
            } while (board.aiBoard[i, j] != Board.Empty);

            Move NewMove = new Move(i, j);
            iPossibleMoves--;

            //Make Move
            Board NewBoard = new Board(board);
            NewBoard.MakeMove(CurrentPlayer, NewMove);
            NewBoard.CheckBoard();

            if (NewBoard.BoardState == GameState.InProgress)
            {
                Move tempMove = GetBestMove(NewBoard, -CurrentPlayer, iBoardSize);
                NewMove.iRank = tempMove.iRank;
            }
            else
            {
                //Assign a rank
                if (NewBoard.BoardState == GameState.Draw)
                    NewMove.iRank = 0;
                else
                {
                    if (NewBoard.BoardState == GameState.ComputerWins)
                        NewMove.iRank = -1;
                    else
                    {
                        if (NewBoard.BoardState == GameState.HumanWins)
                            NewMove.iRank = 1;
                    }
                }
            }

            //Is NewMove the best move encountered at this level so far?
            if (BestMove == null ||
                (CurrentPlayer == TicTacToe.Computer && NewMove.iRank < BestMove.iRank) ||
                (CurrentPlayer == TicTacToe.Human && NewMove.iRank > BestMove.iRank))
            {
                BestMove = NewMove;
            }
        }
        return BestMove;
    }
    
}*/
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?