⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minimax_test.cs

📁 tic tac toe is simple game .I think every people had play it
💻 CS
字号:
/*
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -