Example #1
0
        public static NEIGHBOUR getOppositeNeighbour(NEIGHBOUR argNeighbour)
        {
            switch (argNeighbour)
            {
            case NEIGHBOUR.NORTH:
                return(NEIGHBOUR.SOUTH);

            case NEIGHBOUR.NORTHEAST:
                return(NEIGHBOUR.SOUTHWEST);

            case NEIGHBOUR.EAST:
                return(NEIGHBOUR.WEST);

            case NEIGHBOUR.SOUTHEAST:
                return(NEIGHBOUR.NORTHWEST);

            case NEIGHBOUR.SOUTH:
                return(NEIGHBOUR.NORTH);

            case NEIGHBOUR.SOUTHWEST:
                return(NEIGHBOUR.NORTHEAST);

            case NEIGHBOUR.WEST:
                return(NEIGHBOUR.EAST);

            case NEIGHBOUR.NORTHWEST:
                return(NEIGHBOUR.SOUTHEAST);
            }

            // this code should never be reached
            Console.WriteLine("Error: ThudPiece::getOppositeNeighbour - " + argNeighbour);
            return(NEIGHBOUR.NORTH);
        }
Example #2
0
        private bool isLegalShove(BoardPiece argPiece)
        {
            // Shove: anywhere there is a straight (orthogonal or diagonal) line of adjacent trolls on the board,
            // they may shove the endmost troll in the direction continuing the line, up to as many spaces as there
            // are trolls in the line.
            // As in a normal move, the troll may not land on an occupied square, and any dwarfs in the eight squares
            // adjacent to its final position may immediately be captured.
            // Trolls may only make a shove if by doing so they capture at least one dwarf.

            // if our target location is not occupied
            if (!argPiece.isOccupied())
            {
                // and it is in a line with our location
                if (isInLine(square.getLocation(), argPiece.getLocation()))
                {
                    // if this location neighbours any dwarves
                    if (neighboursDwarves(argPiece))
                    {
                        int       distance  = this.getDistance(square.getBoardPosition(), argPiece.getBoardPosition());
                        NEIGHBOUR direction = ThudPiece.getOppositeNeighbour(this.getDirection(square.getLocation(), argPiece.getLocation()));

                        // iterate over the squares in the direction opposite of our destination
                        // equal to the distance we wish to move
                        // if all squares contain a troll, the shove is legal

                        BoardPiece bp = square;
                        for (int i = 0; i < distance; i++)
                        {
                            if (bp.isOccupied())
                            {
                                if (bp.getOccupant() is TrollPiece)
                                {
                                    if (bp.hasNeighbour(direction))
                                    {
                                        bp = (BoardPiece)bp.getNeighbour(direction);
                                    }
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #3
0
        public bool hasNeighbour(NEIGHBOUR argNeighbour)
        {
            if (myNeighbours.ContainsKey(argNeighbour))
            {
                if (myNeighbours[argNeighbour] != null)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #4
0
        private bool isLegalHurl(BoardPiece argPiece)
        {
            // if our target location is occupied
            if (argPiece.isOccupied())
            {
                // ... by a troll
                if (argPiece.getOccupant() is TrollPiece)
                {
                    // and it is in a line with our location
                    if (isInLine(square.getLocation(), argPiece.getLocation()))
                    {
                        int       distance  = this.getDistance(square.getBoardPosition(), argPiece.getBoardPosition());
                        NEIGHBOUR direction = ThudPiece.getOppositeNeighbour(this.getDirection(square.getLocation(), argPiece.getLocation()));

                        // iterate over the squares in the direction opposite of our destination
                        // equal to the distance we wish to move
                        // if all squares contain a dwarf, the hurl is legal

                        BoardPiece bp = square;
                        for (int i = 0; i < distance; i++)
                        {
                            if (bp.isOccupied())
                            {
                                if (bp.getOccupant() is DwarfPiece)
                                {
                                    if (bp.hasNeighbour(direction))
                                    {
                                        bp = (BoardPiece)bp.getNeighbour(direction);
                                    }
                                    else if (i != distance - 1)
                                    {
                                        return(false);
                                    }
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #5
0
        public void setNeighbour(NEIGHBOUR argNeighbour, ThudPiece argPiece, bool recursive)
        {
            if (myNeighbours.ContainsKey(argNeighbour))
            {
                myNeighbours[argNeighbour] = argPiece;
            }
            else
            {
                myNeighbours.Add(argNeighbour, argPiece);
            }

            if (recursive)
            {
                argPiece.setNeighbour(getOppositeNeighbour(argNeighbour), this, false);
            }
        }
Example #6
0
 public void setNeighbour(NEIGHBOUR argNeighbour, ThudPiece argPiece)
 {
     this.setNeighbour(argNeighbour, argPiece, true);
 }
Example #7
0
 public ThudPiece getNeighbour(NEIGHBOUR argNeighbour)
 {
     return(myNeighbours[argNeighbour]);
 }
Example #8
0
 public void setNeighbour(Hexagon argNeighbour, NEIGHBOUR argArea)
 {
     myNeighbours.Add(argArea, argNeighbour);
 }