示例#1
0
文件: Nest.cs 项目: hannahborje/Ludo
        public Nest(Colors color, Piece[] pieces)
        {
            this.pieces = new Stack<Piece>();
            this.color = color;

            foreach (var piece in pieces)
            {  pushPiece(piece); }
        }
示例#2
0
        private List<int[]> exportPieces(Piece[][] pieces)
        {
            List<int[]> piecesList = new List<int[]>();

                for (int color = 0; color < numOfPlayers; color++)
                {
                    for (int index = 0; index < numOfPiecesPerPlayer; index++)
                    {
                        int piecePosition = pieces[color][index].Position;
                        int pieceSteps = pieces[color][index].Steps;
                        int[] pieceInfo = { piecePosition, color, pieceSteps };
                        piecesList.Add( pieceInfo );
                    }
                }
            return piecesList;
        }
示例#3
0
 /// <summary>
 ///  tryMove(piece)
 /// </summary>
 /// <param name="piece"></param>
 /// <param name="dice"></param>
 private void tryMove(Piece piece, dice dice)
 {
     bool isMoveSuccesful = false;
     ludoBoard.tryMovePiece(piece, dice, ref isMoveSuccesful);
     string debug = (isMoveSuccesful) ? "Move succesful" : "Move not succesful";
     Debug.WriteLine("\n" + debug);
 }
示例#4
0
        /// <summary>
        /// We would like to achieve the following: 
        /// - replacing our last position with null
        /// - knocking pieces out or passing depending on collision with ourselves or others
        /// </summary>
        /// <param name="fromSquare"></param>
        /// <param name="toSquare"></param>
        /// <param name="piece"></param>
        /// <param name="steps"></param>
        /// <param name="requestedSteps"></param>
        /// <returns></returns>
        private bool tryMove(Square fromSquare, Square toSquare, Piece piece, int steps, int requestedSteps)
        {
            if (toSquare.Occupant == null)
            {
                Debug.Write("\nMoving piece to square " );
                move(piece, toSquare, fromSquare, steps);
                return true;
            }
            else
            {
                Piece occupyingPiece = toSquare.Occupant;
                Debug.Write("\nSquare  is occupied");
                if (occupyingPiece.Color == piece.Color)
                {
                    // Two pieces of the same color cannot occupy the same space (pass)
                    return false;
                }
                else
                {
                    // We will now deActivate the colliding piece, since it's not our own
                    // ... and insert our own piece
                    Debug.Write("\nKnocking out piece ");
                    move(piece, toSquare, fromSquare, steps);
                    deActivatePiece(occupyingPiece);
                    if (nests[(int)occupyingPiece.Color].Count == 4)
                    { players[(int)occupyingPiece.Color].Active = false; }

                    return true;
                }
            }
        }
示例#5
0
 /// <summary>
 /// To introduce: move a player from nest to square
 /// </summary>
 /// <param name="piece"></param>
 /// <returns></returns>
 private bool tryIntroducePiece(Piece piece)
 {
     Square firstSquare = squares[(int)piece.Color][0];
     bool isIntroduced = tryMove(null, firstSquare, piece, 0, 0);
     return isIntroduced;
 }
示例#6
0
 /// <summary>
 /// Stack-like behaviour
 /// </summary>
 /// <param name="piece"></param>
 private void pushPieceToNest(Piece piece)
 {
     nests[(int)piece.Color].pushPiece(piece);
 }
示例#7
0
 private void move(Piece piece, Square toSquare, Square fromSquare, int steps)
 {
     if (fromSquare != null) { fromSquare.Occupant = null; }
     toSquare.Occupant = piece;
     piece.Steps += steps;
     piece.Position += steps;
 }
示例#8
0
 public Nest(Colors color, Piece[] pieces)
 {
     this.pieces = pieces;
     this.color = color;
 }
示例#9
0
 private void generatePieces(Colors color)
 {
     pieces[(int)color] = new Piece[numOfPiecesPerPlayer];
     for (int i = 0; i < numOfPiecesPerPlayer; i++)
     {
         pieces[(int)color][i] = new Piece(color, i);
     }
 }
示例#10
0
        /// <summary>
        /// Here we need to consider 3 scenarios:
        /// - If we are about to roll the dice and have a chance at moving to the exit squares 
        /// - chance at moving through the goal
        /// - "normal" behaviour
        /// </summary>
        /// <param name="piece"></param>
        /// <param name="steps"></param>
        /// <param name="isMoveSuccesful"></param>
        public void tryMovePiece(Piece piece, int steps, ref bool isMoveSuccesful)
        {
            int requestedSteps = piece.Steps + steps;

            // 3 scenarios //
            if (requestedSteps == numOfStepsToExit)
            {
                Debug.Write("\nExiting");
                isMoveSuccesful = killPiece(piece);
                checkPlayerDeActivation(piece.Color);
            }
            // Almost quitting
            else if (requestedSteps > numOfStepsToExit)
            {
                Debug.Write(String.Format(
                            "\nGoing to the exit squares. Steps walked: {0}, position: {1}, trying new pos: {2}",
                            piece.Steps, piece.Position, piece.Position + steps));

                // We will have to step back x steps from the goal square (overflow)
                Square currentPosition = locateSquare(piece.Steps, piece.Position, piece.Color);
                calculateNewStepsAfterMissedTarget(piece.Position, requestedSteps, ref steps);
                Square requestedPosition = locateSquare(requestedSteps, piece.Position + steps, piece.Color);

                isMoveSuccesful = tryMove(currentPosition, requestedPosition, piece, steps, requestedSteps);

            }
            else
            {
                Debug.Write(String.Format(
                    "\nSteps walked: {0}, position: {1}, trying new pos: {2}",
                     piece.Steps, piece.Position, piece.Position + steps));

                Square currentPosition = locateSquare(piece.Steps, piece.Position, piece.Color);
                Square requestedPosition = locateSquare(requestedSteps, piece.Position + steps, piece.Color);

                isMoveSuccesful = tryMove(currentPosition, requestedPosition, piece, steps, requestedSteps);
            }
        }
示例#11
0
 public void deActivatePiece(Piece piece)
 {
     nests[(int)piece.Color].pushPiece(piece);
     piece.Active = false;
 }
示例#12
0
 public Square(Colors color, int number)
 {
     this.color = color;
     this.SquareID = number;
     this.occupant = null;
 }
示例#13
0
文件: Nest.cs 项目: hannahborje/Ludo
 public void pushPiece(Piece piece)
 {
     pieces.Push(piece);
 }
示例#14
0
 private bool tryMove(Piece piece, dice dice)
 {
     bool isMoveSuccesful = false;
     ludoBoard.tryMovePiece(piece, dice, ref isMoveSuccesful);
     string debug = (isMoveSuccesful) ? "Rules: Move succesful" : "Rules: Move not succesful";
     Debug.WriteLine("\n" + debug);
     return isMoveSuccesful;
 }
示例#15
0
 /// <summary>
 /// By moving through the goal the piece gets killed
 /// </summary>
 /// <param name="piece"></param>
 private bool killPiece(Piece piece)
 {
     Square currentPosition = locateSquare(piece.Steps, piece.Position, piece.Color);
     currentPosition.Occupant = null;
     piece.Alive = false;
     piece.Active = false;
     return true;
 }
示例#16
0
 private GameState updateGameState(GameState gameState, Piece[][] pieces)
 {
     gameState.Pieces = exportPieces(pieces);
     gameState.Instruction = exportInstruction();
     return gameState;
 }
示例#17
0
 public Square(Colors color, int number)
 {
     this.color    = color;
     this.SquareID = number;
     this.occupant = null;
 }