Esempio n. 1
0
        private void AITakeStone()
        {
            Tuple <int, int> indexes   = takeStoneHeuristic.ChooseWhichStone(blackIsPlaying, board.board);
            string           labelName = Linking.GetLabelName(indexes);
            Label            label     = this.Controls.Find(labelName, true).FirstOrDefault() as Label;

            board.NewLabel = label;
            board.TakeStoneFromBoard(blackIsPlaying, indexes);
            if (!gameWon)
            {
                takeStone      = false;
                blackIsPlaying = !blackIsPlaying;

                if (blackIsPlaying)
                {
                    textBox1.Text = "Black Player";
                }
                else
                {
                    textBox1.Text = "White Player";
                }
            }
            else
            {
                GameWon(blackIsPlaying);
            }
        }
Esempio n. 2
0
        private void AIturnToPlay(Move moveResult)
        {
            if (gamePhase == GamePhase.opening)
            {
                string labelName = Linking.GetLabelName(moveResult.To);
                Label  label     = this.Controls.Find(labelName, true).FirstOrDefault() as Label;
                board.NewLabel = label;

                OpeningPhase(moveResult.To);
                label.Update();

                if (counter == 18)
                {
                    board.NewLabel.Update();
                    gamePhase     = GamePhase.midPhase;
                    textBox1.Text = "End of the opening phase";
                    textBox1.Update();
                    System.Threading.Thread.Sleep(3000);
                    textBox1.Text = "White Player Starts";
                }

                if (takeStone == false)
                {
                    if ((MinimaxVshuman) || (AlfaBetaVShuman))
                    {
                        AIturn = false;
                    }
                }
                else
                {
                    AITakeStone();
                    AIturn = false;
                }
            }
            else if ((gamePhase == GamePhase.midPhase) || (gamePhase == GamePhase.finishing))
            {
                string labelName = Linking.GetLabelName(moveResult.From);
                Label  label     = this.Controls.Find(labelName, true).FirstOrDefault() as Label;
                board.NewLabel = label;

                if ((numberOfBlackStones == 3) && (lastThreeBlack == false) && blackIsPlaying)
                {
                    lastThreeBlack = true;
                    gamePhase      = GamePhase.finishing;
                    MidGamePhase(moveResult.From);
                }
                else if ((numberOfWhiteStones == 3) && (lastThreeWhite == false) && !blackIsPlaying)
                {
                    lastThreeWhite = true;
                    gamePhase      = GamePhase.finishing;
                    MidGamePhase(moveResult.From);
                }
                else
                {
                    MidGamePhase(moveResult.From);
                }

                if (slideStone)
                {
                    labelName      = Linking.GetLabelName(moveResult.To);
                    label          = this.Controls.Find(labelName, true).FirstOrDefault() as Label;
                    board.NewLabel = label;
                    slideStone     = false;
                    board.SlideStone(blackIsPlaying, moveResult.To);
                }

                if (board.IsMill(board.board, board.whiteMills, board.blackMills))
                {
                    textBox1.Text = "Mill, take opponent's stone";
                    AITakeStone();
                    Decider();
                    AIturn = false;
                }
                else
                {
                    Decider();
                    AIturn         = false;
                    blackIsPlaying = !blackIsPlaying;
                    if (blackIsPlaying)
                    {
                        textBox1.Text = "Black Player";
                    }
                    else
                    {
                        textBox1.Text = "White Player";
                    }
                }
            }
        }