Beispiel #1
0
        public void CompMove()
        {
            // For each combination of dice (because it can happen that using them in a different order has a different result
            // e.g. when a piece is taken with the first throw or only one dice is usable on the first throw for a piece
            List <List <int> > diceSeqPermut = new List <List <int> >(); // a list of sequences possible from the throw of the dice e.g. diceHi, diceLo or diceLo, diceHi;
            BGMoveSet          thisMoveSet   = new BGMoveSet();          // a moveSet to work with to find all the combinations

            bestMoveSet.Clear();
            if (aBGRules.IsPossible(myBoard, theirBoard, dice1, dice2))  // check if there's at least one move
            {
                diceSeqPermut = aBGRules.GetDiceSeqPermut(dice1, dice2); // get dice sequences
                foreach (var diceSeq in diceSeqPermut)
                {
                    GetPieceRecurse(thisMoveSet, diceSeq, myBoard, theirBoard);
                }
                foreach (BGMove move in bestMoveSet.BGMoves)
                {
                    BoardUpdate(myBoard, theirBoard, move.FMove, move.TMove); //     update board
                }
            }
            else
            {
                bestMoveSet.BGMoves.Add(new BGMove {
                    FMove = 0, TMove = 0, PieceID = 0, SeqOrder = 0, Di = 0, MoveID = 0
                });
            }
            bestMoveSet.Di1 = dice1;
            bestMoveSet.Di2 = dice2;
            Message         = bestMoveSet.GetMessage(GameOver);
            Notation        = bestMoveSet.GetNotation(false);
            IWin            = GameOver; // if the games ending now then this player must be the winner
        }
Beispiel #2
0
        // Have turns for comp v comp or 1 round for comp v human
        private void HaveAGoC0H1(bool moveMade)
        {
            // This version supports a human playing against the C# opponent (Player 0)
            // called from the play button initially and then from the moveMade event handler
            if (players[player].Human == false) //player == PLAYER0) // this should only be true the first time
            {
                Cout(CompMoveC0());
                if (!endGame)            // the game may have ended now
                {
                    Cout(PrepForNext()); // if it hasn't then it must be human's go
                }
                else
                {
                    Cout(FinishGame() + " won.");
                }
                DisplayBoard(); // HumanPrepV0H1(); // display incl. dice in prep for Human go
            }
            else // it's a human's go
            {
                if (moveMade)                                                            // i.e. not the first time after pressing play if it's a human go
                {
                    if (CheckMove())                                                     // Move is good
                    {
                        BoardUpdate(p1Board, p0Board, aBGBoard.fMove1, aBGBoard.tMove1); // i.e the arrays in main
                        PrintMove(aBGBoard.fMove1, aBGBoard.tMove1, 0, 0, 0, 0, 0, 0);   // i.e. Human move notation
                        txtMessage.Text = "";
                        aMoveRec1.Add(aBGBoard.fMove1);                                  // record human moves for replay / undo
                        aMoveRec1.Add(aBGBoard.fMove1 - aBGBoard.tMove1);
                        numMoves--;                                                      // they may have 2 or 4 to start

                        if (FindLastPiece(p1Board) == 0)                                 // the game may have ended now
                        {
                            UserWin();                                                   // admit defeat
                            Cout(FinishGame() + " won.");
                        }
                    }
                    DisplayBoard(); // whether its final board pos or human move prep you will want to see the board
                    if (numMoves <= 0 && !endGame)
                    {
                        Cout(PrepForNext());
                        Cout(CompMoveC0());      // Computer go

                        if (!endGame)            // the game may have ended now
                        {
                            Cout(PrepForNext()); // if it hasn't then it must be human's go
                        }
                        else // if it has the computer's won
                        {
                            Cout(FinishGame() + " won.");
                        }
                        DisplayBoard(); // whether its final board pos or human move prep you will want to see the board
                    }
                    else // there is more human moving to be done in this turn
                    {
                        if (!aBGRules.IsPossible(p1Board, p0Board, di1, di2) && numMoves > 0) // but they can't
                        {
                            numMoves = 0;
                            PrintMove(0, 0, 0, 0, 0, 0, 0, 0);
                            txtMessage.Text = "There is no possible 2nd move"; // tell them
                            aMoveRec1.Add(aBGBoard.fMove1);                    // record human moves for replay / undo
                            aMoveRec1.Add(aBGBoard.fMove1 - aBGBoard.tMove1);

                            Cout(PrepForNext()); // and it's the computer's turn
                            Cout(CompMoveC0());  // Computer go
                            //txtMessage.Text = message;

                            if (!endGame)            // the game may have ended now
                            {
                                Cout(PrepForNext()); // if it hasn't then it must be human's go
                            }
                            else
                            {
                                Cout(FinishGame() + " won.");
                            }
                            DisplayBoard(); // whether its final board pos or human move prep you will want to see the board
                        }
                    }
                }
                // about to wait for human... check they've something they can do
                while (!aBGRules.IsPossible(p1Board, p0Board, di1, di2) && !endGame)
                {
                    numMoves = 0;                      // while we're waiting for the human to be able to move
                    PrintMove(0, 0, 0, 0, 0, 0, 0, 0); // indicate they can't move
                    txtMessage.Text = "There is no possible human move";
                    aMoveRec1.Add(aBGBoard.fMove1);    // record human moves for replay / undo
                    aMoveRec1.Add(aBGBoard.fMove1 - aBGBoard.tMove1);

                    Cout(PrepForNext());
                    Cout(CompMoveC0()); // Computer go
                    //txtMessage.Text = message;

                    if (!endGame)            // the game may have ended now
                    {
                        Cout(PrepForNext()); // if it hasn't then it must be human's go
                    }
                    else
                    {
                        Cout(FinishGame() + " won.");
                    }
                    DisplayBoard(); // whether its final board pos or human move prep you will want to see the board
                }
            }
        }