Example #1
0
    public Piece GetPiece(IPieceState pieceState)
    {
        ISpaceState iss_source = pieceState.GetSpaceState();

        Space space = this.GetSpace(iss_source.GetLevel(), iss_source.GetRow(), iss_source.GetCol());

        return(space.occupier);
    }
Example #2
0
    public void Move(Move move)
    {
        //Move objects can be passed between games so we
        //have to look up the piece and space owned by this game
        //and check to ensure the move is applicable to this game

        IPieceState ips        = move.piece;
        ISpaceState iss_dest   = move.space;
        ISpaceState iss_source = ips.GetSpaceState();

        ISpaceState this_iss_dest   = this.GetSpaceState(iss_dest.GetLevel(), iss_dest.GetRow(), iss_dest.GetCol());
        ISpaceState this_iss_source = this.GetSpaceState(iss_source.GetLevel(), iss_source.GetRow(), iss_source.GetCol());

        if (!this_iss_source.IsOccupied() || this_iss_source.Occupier().GetPieceType() != ips.GetPieceType() || this_iss_source.Occupier().GetPlayer() != ips.GetPlayer())
        {
            throw new Exception("Invalid move for this simulated game board state.");
        }

        Move((PieceState)this_iss_source.Occupier(), (SpaceState)this_iss_dest);
    }
Example #3
0
    public bool Move(Move move)
    {
        //Move objects can be passed between games so we
        //have to look up the piece and space owned by this game
        //and check to ensure the move is applicable to this game

        IPieceState ips        = move.piece;
        ISpaceState iss_dest   = move.space;
        ISpaceState iss_source = ips.GetSpaceState();

        ISpaceState this_iss_dest   = this.GetSpace(iss_dest.GetLevel(), iss_dest.GetRow(), iss_dest.GetCol());
        ISpaceState this_iss_source = this.GetSpace(iss_source.GetLevel(), iss_source.GetRow(), iss_source.GetCol());

        if (!this_iss_source.IsOccupied() || this_iss_source.Occupier().GetPieceType() != ips.GetPieceType() || this_iss_source.Occupier().GetPlayer() != ips.GetPlayer())
        {
            Debug.Log("Illegal move attempted. Skipping turn." + move.ToString());

            if (!this_iss_source.IsOccupied())
            {
                Debug.Log("Source is not occupied in real game board.");
            }
            else if (this_iss_source.Occupier().GetPieceType() != ips.GetPieceType())
            {
                Debug.Log("A different piece type is at the source location in real game board.");
            }
            else if (this_iss_source.Occupier().GetPlayer() != ips.GetPlayer())
            {
                Debug.Log("A different player owns the piece in the real game board.");
            }

            return(false);
            //throw new Exception("Invalid move for this real game board.");
        }

        Move((Piece)this_iss_source.Occupier(), (Space)this_iss_dest);
        return(true);
    }
Example #4
0
 public override string ToString()
 {
     return(piece.GetPieceType() + "@(" + piece.GetSpaceState().GetLevel() + "," + piece.GetSpaceState().GetRow() + "," + piece.GetSpaceState().GetCol() + ") to (" +
            space.GetLevel() + "," + space.GetRow() + "," + space.GetCol() + ")");
 }