Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        public Tuple <int, int> GetTupleOfIndexes(Label label)
        {
            string labelName = label.Name;
            short  index     = GetIndexOfStone(labelName);

            return(Linking.GetIndexesOnBoard(index));
        }
Ejemplo n.º 3
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";
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public Move[] GetIndexesOfPossibleMoves(bool blackIsPLaying, PlaceOnBoardIs[,] board)
        {
            Move[]             indexesOfPossibleMoves  = new Move[36];
            Tuple <int, int>[] adjacentVacantPositions = new Tuple <int, int> [4];

            if (Form1.gamePhase == Form1.GamePhase.opening)
            {
                for (short i = 0; i < 36; i++)
                {
                    Tuple <int, int> tupleOfINdexes = Linking.GetIndexesOnBoard(i);
                    if (tupleOfINdexes.Item1 != -1)
                    {
                        if (board[tupleOfINdexes.Item1, tupleOfINdexes.Item2] == PlaceOnBoardIs.free)
                        {
                            indexesOfPossibleMoves[i] = new Move(tupleOfINdexes.Item1, tupleOfINdexes.Item2, -1, -1, false, blackIsPLaying);
                        }
                        else
                        {
                            indexesOfPossibleMoves[i] = new Move(-1, -1, -1, -1, false, blackIsPLaying);
                        }
                    }
                    else
                    {
                        indexesOfPossibleMoves[i] = new Move(-1, -1, -1, -1, false, blackIsPLaying);
                    }
                }
            }
            else
            {
                short helper1 = 0;
                short helper2 = 0;
                if (blackIsPLaying)
                {
                    for (short i = 0; i < 24; i++)
                    {
                        Tuple <int, int> tupleOfINdexes = Linking.GetIndexesOnBoard(i);
                        if (board[tupleOfINdexes.Item1, tupleOfINdexes.Item2] == PlaceOnBoardIs.blackOccupied)
                        {
                            adjacentVacantPositions = GetAdjacentVacantPositions(tupleOfINdexes.Item1, tupleOfINdexes.Item2, board);

                            for (int j = 0; j < 4; j++)
                            {
                                indexesOfPossibleMoves[helper2 * 4 + helper1] = new Move(adjacentVacantPositions[j].Item1,
                                                                                         adjacentVacantPositions[j].Item2, tupleOfINdexes.Item1,
                                                                                         tupleOfINdexes.Item2, false, blackIsPLaying);
                                helper1++;
                            }
                            helper2++;
                            helper1 = 0;
                        }
                    }
                }
                else
                {
                    for (short i = 0; i < 24; i++)
                    {
                        Tuple <int, int> tupleOfINdexes = Linking.GetIndexesOnBoard(i);
                        if (board[tupleOfINdexes.Item1, tupleOfINdexes.Item2] == PlaceOnBoardIs.whiteOccupied)
                        {
                            adjacentVacantPositions = GetAdjacentVacantPositions(tupleOfINdexes.Item1, tupleOfINdexes.Item2, board);

                            for (int j = 0; j < 4; j++)
                            {
                                indexesOfPossibleMoves[helper2 * 4 + helper1] = new Move(adjacentVacantPositions[j].Item1,
                                                                                         adjacentVacantPositions[j].Item2, tupleOfINdexes.Item1,
                                                                                         tupleOfINdexes.Item2, false, blackIsPLaying);
                                helper1++;
                            }
                            helper2++;
                            helper1 = 0;
                        }
                    }
                }
            }
            return(indexesOfPossibleMoves);
        }