예제 #1
0
        public int getMoveScore(BoardPiece argDestination)
        {
            if (isLegalMove(argDestination) || isLegalAttack(argDestination))
            {
                return(scoreMove(argDestination));
            }

            // return -1 for all impossible moves
            return(-1);
        }
예제 #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);
        }
예제 #3
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);
        }
예제 #4
0
        public void setSquare(BoardPiece argPiece)
        {
            if (square != null)
            {
                square.setOccupant(null);
            }

            square = argPiece;

            if (square != null)
            {
                this.setLocation(square.getLocation());
            }
        }
예제 #5
0
        public override bool isLegalAttack(BoardPiece argPiece)
        {
            if (hasMoved())
            {
                if (argPiece.isOccupied())
                {
                    if (argPiece.getOccupant() is DwarfPiece)
                    {
                        if (square.isNeighbour(argPiece))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #6
0
        private bool neighboursDwarves(BoardPiece argPiece)
        {
            foreach (NEIGHBOUR n in Enum.GetValues(typeof(NEIGHBOUR)))
            {
                if (argPiece.hasNeighbour(n))
                {
                    BoardPiece p = (BoardPiece)argPiece.getNeighbour(n);

                    if (p.isOccupied())
                    {
                        if (p.getOccupant() is DwarfPiece)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #7
0
        public override bool isLegalMove(BoardPiece argPiece)
        {
            if (logic.getTurn() == SIDE.TROLL)
            {
                if (square.isNeighbour(argPiece))
                {
                    if (!argPiece.isOccupied())
                    {
                        return(true);
                    }
                }
                else
                {
                    return(isLegalShove(argPiece));
                }
            }

            return(false);
        }
예제 #8
0
        public override bool isLegalMove(BoardPiece argPiece)
        {
            // early out
            if (logic.getTurn() == SIDE.TROLL)
            {
                return(false);
            }

            Point myLocation  = square.getBoardPosition();
            Point destination = argPiece.getBoardPosition();

            // early out
            if (!isInLine(myLocation, destination))
            {
                return(false);
            }

            GameLogic.NEIGHBOUR direction = getDirection(myLocation, destination);

            BoardPiece ep = (BoardPiece)square.getNeighbour(direction);

            // check all squares in the direction of our destination
            while (!ep.isOccupied())
            {
                if (ep == argPiece)
                {
                    return(true);
                }

                if (ep.hasNeighbour(direction))
                {
                    ep = (BoardPiece)ep.getNeighbour(direction);
                }
                else
                {
                    break;
                }
            }

            return(false);
        }
예제 #9
0
        private void setHighlights(bool on)
        {
            // early out
            if (logic.getTurn() == SIDE.TROLL)
            {
                return;
            }


            foreach (NEIGHBOUR n in Enum.GetValues(typeof(NEIGHBOUR)))
            {
                if (square.hasNeighbour(n))
                {
                    BoardPiece ep = (BoardPiece)square.getNeighbour(n);

                    while (!ep.isOccupied())
                    {
                        if (on)
                        {
                            ep.highlight(false);
                        }
                        else
                        {
                            ep.resetImage();
                        }

                        if (ep.hasNeighbour(n))
                        {
                            ep = (BoardPiece)ep.getNeighbour(n);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
예제 #10
0
 protected override int scoreMove(BoardPiece argDestination)
 {
     return(0);
 }
예제 #11
0
 private void movePawn(PawnPiece pawn, BoardPiece piece)
 {
     piece.setOccupant(pawn);
     pawn.move();
 }
예제 #12
0
 public override bool isLegalAttack(BoardPiece argPiece)
 {
     return(isLegalHurl(argPiece));
 }
예제 #13
0
 private void removePawn(BoardPiece piece)
 {
 }
예제 #14
0
 abstract public bool isLegalMove(BoardPiece argPiece);
예제 #15
0
        public void squareSelected(BoardPiece argPiece)
        {
            if (argPiece.isOccupied() && currentPhase != PHASE.ATTACK)
            {
                selectPawn(argPiece.getOccupant());
            }

            // TODO: move 'move code' into board piece classes
            if (selectedPawn != null)
            {
                switch (this.getTurn())
                {
                case SIDE.DWARF:
                    if (argPiece.isOccupied())
                    {
                        // hurl
                        if (selectedPawn.isLegalAttack(argPiece))
                        {
                            board.removePiece(argPiece.getBoardPosition());
                            movePawn(selectedPawn, argPiece);
                            nextTurn();
                        }
                    }
                    else
                    {
                        // move
                        if (selectedPawn.isLegalMove(argPiece))
                        {
                            movePawn(selectedPawn, argPiece);
                            nextTurn();
                        }
                    }
                    break;

                case SIDE.TROLL:
                    switch (currentPhase)
                    {
                    case PHASE.MOVE:
                        if (selectedPawn.isLegalMove(argPiece))
                        {
                            movePawn(selectedPawn, argPiece);
                            currentPhase = PHASE.ATTACK;

                            if (!selectedPawn.hasMovesLeft(currentPhase))
                            {
                                nextTurn();
                            }
                        }
                        break;

                    case PHASE.ATTACK:
                        if (selectedPawn.isLegalAttack(argPiece))
                        {
                            board.removePiece(argPiece.getBoardPosition());
                        }

                        if (!selectedPawn.hasMovesLeft(currentPhase))
                        {
                            nextTurn();
                        }
                        break;
                    }
                    break;
                }
            }

            evaluate();
        }
예제 #16
0
 abstract protected int scoreMove(BoardPiece argDestination);
예제 #17
0
 abstract public bool isLegalAttack(BoardPiece argPiece);
예제 #18
0
        private void createBoard()
        {
            //make pieces
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 15; y++)
                {
                    if (!isCorner(x, y))
                    {
                        bool even = false;
                        if ((x % 2 == 0 && y % 2 == 0) || (x % 2 == 1 && y % 2 == 1))
                        {
                            even = true;
                        }

                        BoardPiece tp = new BoardPiece(x * 66 + offset, y * 66 + offset, even);
                        tp.setLogic(logic);
                        tp.setBoardPosition(x, y);
                        this.addActor(tp);
                        pieces[x, y] = tp;
                    }
                }
            }

            // set neighbours
            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 15; y++)
                {
                    if (pieceExists(x, y))
                    {
                        ThudPiece current = pieces[x, y];

                        if (pieceExists(x, y - 1))
                        {
                            current.setNeighbour(NEIGHBOUR.NORTH, pieces[x, y - 1]);
                        }

                        if (pieceExists(x + 1, y - 1))
                        {
                            current.setNeighbour(NEIGHBOUR.NORTHEAST, pieces[x + 1, y - 1]);
                        }

                        if (pieceExists(x + 1, y))
                        {
                            current.setNeighbour(NEIGHBOUR.EAST, pieces[x + 1, y]);
                        }

                        if (pieceExists(x + 1, y + 1))
                        {
                            current.setNeighbour(NEIGHBOUR.SOUTHEAST, pieces[x + 1, y + 1]);
                        }

                        if (pieceExists(x, y + 1))
                        {
                            current.setNeighbour(NEIGHBOUR.SOUTH, pieces[x, y + 1]);
                        }

                        if (pieceExists(x - 1, y + 1))
                        {
                            current.setNeighbour(NEIGHBOUR.SOUTHWEST, pieces[x - 1, y + 1]);
                        }

                        if (pieceExists(x - 1, y))
                        {
                            current.setNeighbour(NEIGHBOUR.WEST, pieces[x - 1, y]);
                        }

                        if (pieceExists(x - 1, y - 1))
                        {
                            current.setNeighbour(NEIGHBOUR.NORTHWEST, pieces[x - 1, y - 1]);
                        }
                    }
                }
            }
        }
예제 #19
0
 public override bool isLegalAttack(BoardPiece argPiece)
 {
     return(false);
 }