コード例 #1
0
ファイル: Program.cs プロジェクト: Thinker222/Othello_MiniMax
        static void Main(string[] args)
        {
            Othello_Board othello_Board = new Othello_Board();

            othello_Board.SetBoard();
            othello_Board.PrintBoard();
            bool can_take_moves = true;

            while (can_take_moves)
            {
                othello_Board.PrintBoard();
                var moves = Othello_Minimax.GetBestMove(new Othello_Board(othello_Board), State.White, 5);
                if (moves.Item3 == -1)
                {
                    can_take_moves = false;
                }

                else
                {
                    othello_Board.UpdateBoard(moves.Item3, State.White, true);
                }

                var moves2 = Othello_Minimax.GetBestMove(new Othello_Board(othello_Board), State.Black, 1);
                if (moves2.Item3 == -1)
                {
                    can_take_moves = false;
                }

                else
                {
                    othello_Board.UpdateBoard(moves2.Item3, State.Black, true);
                    can_take_moves = true;
                }

                //var white_moves = othello_Board.PossibleMoves(State.White);
                //if(white_moves.Count > 0)
                //{
                //    othello_Board.UpdateBoard(white_moves[0], State.White, true);
                //}
                //else
                //{
                //    can_take_moves = false;
                //}


                var score = othello_Board.ScoreGame();
                Console.WriteLine("\nBlack:\t" + score.Item1 + "\nWhite:\t" + score.Item2 + "\n");
            }
            int x = 2;

            Console.ReadKey();
        }
コード例 #2
0
        public static Tuple <int, int, int> GetBestMove(Othello_Board board, State state, int depth, int last_move = -1)
        {
            // Make a copy of the board
            Othello_Board board_copy = new Othello_Board(board);

            // If there is a move execute it
            if (last_move != -1)
            {
                board_copy.UpdateBoard(last_move, StateHandler.GetOppositeState(state), true);
                //  Console.WriteLine("PRinting board");
                //  board_copy.PrintBoard();
            }
            var possible_moves = board_copy.PossibleMoves(state);
            Tuple <int, int, int> current_best = new Tuple <int, int, int>(0, 0, 0);
            int best_value = int.MinValue;
            int best_move  = -1;

            if (possible_moves.Count > 0 && depth > 0)
            {
                foreach (int move in possible_moves)
                {
                    Tuple <int, int, int> temp_best = GetBestMove(new Othello_Board(board_copy), StateHandler.GetOppositeState(state), depth - 1, move);
                    int temp_value = 0;
                    if (state == State.Black)
                    {
                        temp_value = temp_best.Item1 - temp_best.Item2;
                    }
                    else
                    {
                        temp_value = temp_best.Item2 - temp_best.Item1;
                    }
                    if (temp_value > best_value)
                    {
                        best_value   = temp_value;
                        current_best = temp_best;
                        best_move    = move;
                    }
                }
                return(new Tuple <int, int, int>(current_best.Item1, current_best.Item2, best_move));
            }

            else
            {
                var score = board_copy.EvaluateGameState();
                //if(score.Item1 + score.Item2 > 50)
                //{
                //    score =
                //}
                return(new Tuple <int, int, int>(score.Item1, score.Item2, last_move));
            }
        }