コード例 #1
0
ファイル: Move.cs プロジェクト: tempestrock/Kalaha
        /// <summary>
        /// Returns the backward move of the given move.
        /// A "backward move" of a move has all the seed movements in the converse order, and each seed movement has swapped "FromPit" and "ToPit".
        /// </summary>
        public Move GetBackwardMove()
        {
            Move backMove = new Move();

            // Walk backwards through the list of seed movements:
            for (int index = _seedMovementList.Count - 1; index >= 0;  --index)
            {
                // Take the seed movement at position "index":
                SeedMovement origSeedMovement = _seedMovementList[index];

                // Create a new seed movement that has swapped FromPit and ToPit:
                SeedMovement backSeedMovement = new SeedMovement(origSeedMovement.ToPit, origSeedMovement.FromPit, origSeedMovement.NumberOfSeeds);

                // Add the new seed movement to the backward move:
                backMove.AddSeedMovement(backSeedMovement);
            }

            return backMove;
        }
コード例 #2
0
ファイル: Gameboard.cs プロジェクト: tempestrock/Kalaha
        /// <summary>Moves all seeds into the respective Kalahs.</summary>
        public Move CollectFinalSeeds(Player firstPlayer, Player secondPlayer)
        {
            Move move = new Move();
            Player currentPlayer = firstPlayer;
            for (int playerIndex = 0; playerIndex < 2; ++playerIndex)
            {
                Pit currentPlayersKalah = GetKalahOfPlayer(currentPlayer);
                int internalIndexOfKalah = GetInternalIndexOfKalah(currentPlayer);

                for (int pitIndex = 0; pitIndex < _numHousesPerPlayer; ++pitIndex)
                {
                    Pit currentPit = GetPitOfPlayer(currentPlayer, pitIndex);

                    if (currentPit.GetNumberofSeeds() > 0)
                    {
                        int currentPitsInternalIndex = GetInternalPitIndex(currentPlayer, pitIndex);
                        move.AddSeedMovement(new SeedMovement(currentPitsInternalIndex, internalIndexOfKalah, currentPit.GetNumberofSeeds()));

                        currentPlayersKalah.AddSeeds(currentPit.GetNumberofSeeds());
                        currentPit.RemoveAllSeeds();
                    }
                }
                currentPlayer = secondPlayer;
            }

            return move;
        }