Beispiel #1
0
    private void DrawBoard()
    {
        GameService._drawSize = 100;
        var        hexes = GameService.GetHexagonsForBoard(currentBoard);
        GameObject existingSpotObject = GameObject.Find("ExistingMoveSpot");

        foreach (HexagonDrawing hexDrawing in hexes)
        {
            BeetleStack stack = hexDrawing.piece as BeetleStack;
            if (stack != null)
            {
                for (int i = 0; i < stack.Pieces.Count; i++)
                {
                    if (stack.Pieces[i] == null)
                    {
                        continue;
                    }
                    SetPiecePosition(stack.Pieces[i], hexDrawing.center, i);
                }
            }
            else
            {
                SetPiecePosition(hexDrawing.piece, hexDrawing._center);
            }
        }
    }
Beispiel #2
0
        private Piece HandleBeetleFromStackMove(BeetleStack stack, Hex from, Hex to)
        {
            Piece actualPiece = stack.top;
            Piece newPiece    = BeetleStack.PopBeetleStack(stack);

            _boardPieceArray[from.column, from.row] = newPiece;
            _playedPieces.Remove(stack);
            _playedPieces.Add(newPiece, from);
            return(actualPiece);
        }
Beispiel #3
0
        public void CheckBeetleStackContains()
        {
            Ant         ant     = new Ant(PieceColor.Black, 1);
            Beetle      beetle  = new Beetle(PieceColor.Black, 1);
            Beetle      beetle2 = new Beetle(PieceColor.Black, 2);
            Beetle      beetle3 = new Beetle(PieceColor.White, 1);
            Beetle      beetle4 = new Beetle(PieceColor.White, 2);
            BeetleStack bs      = new BeetleStack(beetle3, new BeetleStack(ant, beetle));

            Assert.IsTrue(bs.Contains(beetle3));
            Assert.IsTrue(bs.Contains(ant));
            Assert.IsFalse(bs.Contains(beetle4));
        }
Beispiel #4
0
        public void CheckBeetleStackEquality()
        {
            Ant         ant     = new Ant(PieceColor.Black, 1);
            Beetle      beetle  = new Beetle(PieceColor.Black, 1);
            Beetle      beetle2 = new Beetle(PieceColor.Black, 2);
            Beetle      beetle3 = new Beetle(PieceColor.White, 1);
            Beetle      beetle4 = new Beetle(PieceColor.White, 2);
            BeetleStack bs      = new BeetleStack(beetle3, new BeetleStack(ant, beetle));

            BeetleStack bs2 = new BeetleStack(beetle3, new BeetleStack(ant, beetle));

            BeetleStack bs3 = new BeetleStack(ant, beetle4);

            Assert.IsTrue(bs.Equals(bs2));
            Assert.IsFalse(bs3.Equals(bs2));
            Assert.IsFalse(bs2.Equals(beetle3));
        }
Beispiel #5
0
        private void HandleBeetleToStackMove(Beetle movingPiece, Piece referencePiece, Hex from, Hex to)
        {
            // beetle climbing
            BeetleStack newStack;

            if (referencePiece is BeetleStack)
            {
                newStack = new BeetleStack(movingPiece, (BeetleStack)referencePiece);
            }
            else
            {
                // new beetle stack
                newStack = new BeetleStack(referencePiece, movingPiece);
            }
            _playedPieces.Remove(referencePiece);
            _boardPieceArray[to.column, to.row] = newStack;
            _playedPieces.Add(newStack, to);
        }
Beispiel #6
0
 public bool TryGetHexOfPlayedPiece(Piece piece, out Hex hex)
 {
     // look for it non-stacked
     if (_playedPieces.TryGetValue(piece, out hex))
     {
         return(true);
     }
     else
     {
         // look in all the beetle stacks
         BeetleStack beetleStack = _playedPieces.Keys
                                   .OfType <BeetleStack>()
                                   .FirstOrDefault(bs => bs.Contains(piece));
         if (null != beetleStack)
         {
             hex = _playedPieces[beetleStack];
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Produces valid notation, but does not validate the move for the given board.
        /// </summary>
        /// <param name="move"></param>
        /// <param name="board"></param>
        /// <returns></returns>
        internal static string GetNotationForMove(Move move, Board board)
        {
            //TODO fix problem where beetle moves generate a "next to myself" reference piece
            string referencePieceNotation;
            string targetPieceNotation = GetNotationForPiece(move.pieceToMove);

            if (board.hivailableSpaces.Count == 1)
            {
                referencePieceNotation = ".";
            }
            else if (move.referencePiece != null)
            {
                referencePieceNotation = GetNotationForPiece(move.referencePiece);
                referencePieceNotation = string.Format(Neighborhood.neighborDirectionNotationTemplates[(int)move.targetPosition], referencePieceNotation);
            }
            else if (!move.hex.Equals(Board.invalidHex))
            {
                Piece refPiece = null;
                if (board.TryGetPieceAtHex(move.hex, out refPiece))
                {
                    // assume this is a beetle moving on top of another piece
                    referencePieceNotation = GetNotationForPiece(refPiece);
                }
                else
                {
                    Hex      refHex      = Board.invalidHex;
                    Position refPosition = Position.center;
                    bool     found       = false;
                    int      i           = 0; // zero is center.  we dont care about center
                    while (!found && i < Neighborhood.neighborDirections.Length)
                    {
                        i++;
                        refHex      = Neighborhood.neighborDirections[i] + move.hex;
                        refPosition = Neighborhood.GetOpposite((Position)i);
                        if (board.TryGetPieceAtHex(refHex, out refPiece))
                        {
                            found = !refPiece.Equals(move.pieceToMove);
                        }
                    }
                    // must be a first move
                    if (!found)
                    {
                        referencePieceNotation = ".";
                    }
                    else
                    {
                        referencePieceNotation = GetNotationForPiece(refPiece);
                        if (referencePieceNotation == targetPieceNotation)
                        {
                            if (refPiece is BeetleStack)
                            {
                                refPiece = BeetleStack.PopBeetleStack((BeetleStack)refPiece);
                            }
                            else
                            {
                            }
                            referencePieceNotation = GetNotationForPiece(refPiece);
                        }
                        referencePieceNotation = string.Format(Neighborhood.neighborDirectionNotationTemplates[(int)refPosition], referencePieceNotation);
                    }
                }
            }
            else
            {
                // must be a first move
                referencePieceNotation = ".";
            }
            return(targetPieceNotation + " " + referencePieceNotation);
        }