Пример #1
0
        private double scoreNode(Node nodo, ActivePlayer player, int depth)
        {
            double score = 0;

            if (Judge.CheckForVictory(player, nodo.Board))
            {
                if (depth == 0)
                {
                    score = double.PositiveInfinity;
                }
                else
                {
                    score += Math.Pow(10.0, maximumDepth - depth);
                }
            }
            else if (Judge.CheckForVictory(getOpponent(player), nodo.Board))
            {
                score += -Math.Pow(100
                                   , maximumDepth - depth);
            }
            else
            {
                foreach (var varianteContrincante in nodo.Variants)
                {
                    score += scoreNode(varianteContrincante, player, depth + 1);
                }
            }

            return(score);
        }
Пример #2
0
            public override void Play()
            {
                while (true)
                {
                    iODevice.Output("");
                    iODevice.Output(board.ToString());
                    iODevice.Output("");

                    int move = activePlayer.RequestMove(board);
                    iODevice.Output(board.ToString());
                    if (!board.MakePlay(activePlayer.Color, move, out board))
                    {
                        iODevice.Output("Row is full. Try again.");
                        continue;
                    }

                    if (Judge.CheckForVictory(activePlayer.Color, board))
                    {
                        iODevice.Output(board.ToString());
                        iODevice.Output("");

                        if (activePlayer == computerPlayer)
                        {
                            iODevice.Accept("I'm sorry player {0}. I won again...", humanPlayer.Color);
                        }
                        else
                        {
                            iODevice.Accept("Congratulations player {0}! ¡You won!", humanPlayer.Color);
                        }
                        break;
                    }

                    if (board.NumberOfEmptyCells == 0)
                    {
                        iODevice.Output(board.ToString());
                        iODevice.Output("");
                        iODevice.Accept("¡Draw! I didnt loose...again");
                        break;
                    }

                    changeActivePlayer();
                }
            }