Ejemplo n.º 1
0
        /* Returns a list of moves naively available to that piece.
         * It ignores the state of the board and any pieces that might be
         * in the way at this stage. */
        public List<Move> getAvailableMoves()
        {
            Coord fromPos = currentPosition; //the pos from which this piece will move

            List<Move> moves = new List<Move>();

            Dictionary<string, int> instruction;
            Move move;

            if ((ptype == "d_man") || (ptype == "d_king"))
            {
                // y direction determined from 'player'
                // the JMP moves will contain reference to the jmpd tile/piece
                instruction = MoveInstructionDatabase.getAdvanceMoveWest(player);
                move = new Move(fromPos, "mv", instruction);
                moves.Add(move);

                // since this is a jump type move, the move object will also know to
                // generate the coord which was jumped from the instruction
                // the instruction will accordingly provide this information
                instruction = MoveInstructionDatabase.getAdvanceJumpWest(player);
                move = new Move(fromPos, "jmp", instruction);
                moves.Add(move);

                instruction = MoveInstructionDatabase.getAdvanceMoveEast(player);
                move = new Move(fromPos, "mv", instruction);
                moves.Add(move);

                instruction = MoveInstructionDatabase.getAdvanceJumpEast(player);
                move = new Move(fromPos, "jmp", instruction);
                moves.Add(move);

            }

            if (ptype == "d_king") // also compute the move on the opposite
                                   // y direction (retreat) for the king piece
            {

                instruction = MoveInstructionDatabase.getRetreatMoveWest(player);
                move = new Move(fromPos, "mv", instruction);
                moves.Add(move);

                instruction = MoveInstructionDatabase.getRetreatJumpWest(player);
                move = new Move(fromPos, "jmp", instruction);
                moves.Add(move);

                instruction = MoveInstructionDatabase.getRetreatMoveEast(player);
                move = new Move(fromPos, "mv", instruction);
                moves.Add(move);

                instruction = MoveInstructionDatabase.getRetreatJumpEast(player);
                move = new Move(fromPos, "jmp", instruction);
                moves.Add(move);
            }
            return moves;
        }
Ejemplo n.º 2
0
 /* Check if a given move's toPosition is lying legally on the
  * board. If it is not within the legal range, false is returned.
  * Todo: more elegant way of doing this with a range? */
 private bool isToPosOnBoard(Move move)
 {
     int x = move.ToPos.X;
     int y = move.ToPos.Y;
     return (x >= 0) && (x < size) && (y >= 0) && (y < size);
 }