Inheritance: MonoBehaviour
        /// <summary>
        /// Display a board square.
        /// </summary>
        /// <param name="square">The square to be displayed.</param>
        /// <param name="highlightSquare">Highlight the square? Defaults to false.</param>
        /// /// <param name="highlightSquare">Highlight the piece? Defaults to false.</param>
        private void DisplayBoardSquare(BoardSquare square, bool highlightSquare = false, bool highlightPiece = false)
        {
            ConsoleColor squareBgColor;

            squareBgColor = square.IsPlayable ?
                            ConsoleSettings.ColorBoardSquarePlayableBg : ConsoleSettings.ColorBoardSquareBg;

            if (highlightSquare)
            {
                squareBgColor = ConsoleSettings.ColorBoardSquareHighlightedBg;
            }

            SetConsoleColor(squareBgColor, ConsoleSettings.ColorBoardSquareFg);

            SetCursorPosition(ConsoleSettings.PosBoardLeft + square.Pos.Column * ConsoleSettings.SizeBoardSquare,
                              ConsoleSettings.PosBoardTop + square.Pos.Row);

            // Go through the square's "tiles"
            for (int i = 0; i < ConsoleSettings.SizeBoardSquare; i++)
            {
                if (i == ConsoleSettings.PosPieceIndex && square.Piece != null)
                {
                    if (highlightPiece)
                    {
                        SetConsoleColor(squareBgColor, ConsoleSettings.ColorSelectedPieceFg);
                    }

                    Console.Write(square.Piece.Unicode);
                    continue;
                }

                Console.Write(" ");
            }
        }
Exemple #2
0
        /// <summary>
        /// Performs setup of new game board, prepared for player 1 to start placing
        /// treasure and initial pieces
        /// </summary>
        /// <param name="phase">Game phase before action</param>
        /// <param name="board">Board state before action, ignored</param>
        /// <param name="newPhase">Game phase after action</param>
        /// <param name="newBoard">Board state after action</param>
        /// <returns>True if action was performed successfully</returns>
        public bool PerformAction(GamePhase phase, GameBoard board, out GamePhase newPhase, out GameBoard newBoard)
        {
            if (phase != GamePhase.None)
            {
                newPhase = phase;
                newBoard = board;
                return(false);
            }

            newPhase = GamePhase.Player1PreSetup;
            newBoard = new GameBoard();
            for (var i = 1; i <= 8; i++)
            {
                for (var j = 1; j <= 8; j++)
                {
                    var newSquare = new BoardSquare(new BoardLocation(i, j), BoardSquareContents.Empty);
                    newBoard.Squares[newSquare.Position] = newSquare;
                }
            }

            foreach (var c in "AZZRIBJVLTPYSDWNMCFXEKG")
            {
                newBoard.Player1Reserve.Add((Shape)c);
                newBoard.Player2Reserve.Add((Shape)c);
            }

            return(true);
        }
 public void AppendMoves(BoardSquare originSquare, Position.Position position, List <Move> moves)
 {
     for (int i = 0; i < rayDeltas.Length; ++i)
     {
         AppendRayMoves(originSquare, position, rayDeltas[i], moves);
     }
 }
        public void AppendMoves(BoardSquare originSquare, Position.Position position, List <Move> moves)
        {
            var board        = position.Board;
            var playerToMove = position.PlayerToMove;
            var moveDeltas   = GetMoveDeltas();
            var moveBuilder  = new MoveBuilder(GetPiece(), originSquare);

            for (int i = 0; i < moveDeltas.Length; ++i)
            {
                if (!moveDeltas[i].IsCanApplyTo(originSquare))
                {
                    continue;
                }
                var destSquare = moveDeltas[i].GetDestSquare(originSquare);
                if (board.IsEmpty(destSquare))
                {
                    moves.Add(moveBuilder.SetDestSquare(destSquare).Build());
                }
                else
                {
                    var pieceAtDestSquare = board.GetPieceAt(destSquare);
                    if (pieceAtDestSquare.player != playerToMove)
                    {
                        moves.Add(moveBuilder
                                  .SetDestSquare(destSquare)
                                  .SetCapture(pieceAtDestSquare.piece)
                                  .Build());
                    }
                }
            }
        }
        private void AppendRayMoves(
            BoardSquare originSquare,
            Position.Position position,
            MoveDelta rayDelta,
            List <Move> moves)
        {
            var board       = position.Board;
            var moveBuilder = new MoveBuilder(piece, originSquare);

            var currentSquare = originSquare;

            while (rayDelta.IsCanApplyTo(currentSquare))
            {
                currentSquare = rayDelta.GetDestSquare(currentSquare);
                if (board.IsEmpty(currentSquare))
                {
                    moves.Add(moveBuilder.SetDestSquare(currentSquare).Build());
                }
                else
                {
                    var obstacle = board.GetPieceAt(currentSquare);
                    if (obstacle.player != position.PlayerToMove)
                    {
                        moves.Add(moveBuilder
                                  .SetDestSquare(currentSquare)
                                  .SetCapture(obstacle.piece)
                                  .Build());
                    }
                    break;
                }
            }
        }
Exemple #6
0
        public static BoardSquare getMagicMoves(BoardSquare position, BoardSquare allPieces, bool isRook)
        {
            if (!initialized)
            {
                initialize();
                initialized = true;
            }
            int         bitIndex = BitBoard.PositionIndexFromBoardSquare(position);
            BoardSquare mask, occupancy;
            int         shifts, magicIndex;
            ulong       magicNumber;

            if (isRook)
            {
                mask        = occupancyMaskRook[bitIndex];
                magicNumber = magicNumberRook[bitIndex];
                shifts      = magicNumberShiftsRook[bitIndex];
                occupancy   = allPieces & mask;
                magicIndex  = (int)(((ulong)occupancy * magicNumber) >> shifts);
                return(magicMovesRook[bitIndex][magicIndex]);
            }
            else
            {
                mask        = occupancyMaskBishop[bitIndex];
                magicNumber = magicNumberBishop[bitIndex];
                shifts      = magicNumberShiftsBishop[bitIndex];
                occupancy   = allPieces & mask;
                magicIndex  = (int)(((ulong)occupancy * magicNumber) >> shifts);
                return(magicMovesBishop[bitIndex][magicIndex]);
            }
        }
Exemple #7
0
 /// <summary>
 /// This routine will grab ahold of a piece and allow us to move it around
 /// the chess board.
 /// </summary>
 /// <param name="mouse"></param>
 public void pickupPiece(MouseEventArgs mouse)
 {
     if (!isDragging)
     {
         coSourceSquare = coChessBitmap.findSquare(mouse.X, mouse.Y);
         // Found a source square.
         if (coSourceSquare != null)
         {
             // Do we have a hold of one of the little dudes?
             if (coSourceSquare.Piece != Chess.Pieces.NONE)
             {
                 // Let everyone know that we are dragging the little dude around.
                 isDragging           = true;
                 coMovingSquare       = coSourceSquare.Square;
                 coPoint              = new Point(coMovingSquare.X + coMovingSquare.Width / 2, coMovingSquare.Y + coMovingSquare.Height / 2);
                 coPiece              = coSourceSquare.Piece;
                 coSourceSquare.Piece = Chess.Pieces.NONE;
                 Graphics offScreenDC = Graphics.FromImage(coChessBitmap.coBmpBoard);
                 offScreenDC.DrawImage(coSourceSquare.Background, coSourceSquare.Square);
                 Cursor.Current = (Cursor)coChessCursors[Chess.Pieces.CLOSEDHAND];
                 // If we don't do this then resources do not get released.  Memory leaks...
                 offScreenDC.Dispose();
             }
         }
     }
 }
Exemple #8
0
        private BoardSquare[,] initiateBoard(int i_Size)
        {
            BoardSquare[,] BoardSquares = new BoardSquare[i_Size, i_Size];
            int NumberOfCheckersLine = (i_Size / 2) - 1;

            for (int i = 0; i < NumberOfCheckersLine; i++)
            {
                for (int j = 0; j < i_Size; j++)
                {
                    if (i % 2 == 0 && j % 2 != 0)
                    {
                        BoardSquares[i, j] = new BoardSquare(eShape.Black, new Location(i, j), ePlayerColor.Black);
                        BoardSquares[i_Size - i - 1, i_Size - j - 1] = new BoardSquare(eShape.White, new Location(i_Size - i - 1, i_Size - j - 1), ePlayerColor.White);
                    }
                    else if (i % 2 != 0 && j % 2 == 0)
                    {
                        BoardSquares[i, j] = new BoardSquare(eShape.Black, new Location(i, j), ePlayerColor.Black);
                        BoardSquares[i_Size - i - 1, i_Size - j - 1] = new BoardSquare(eShape.White, new Location(i_Size - i - 1, i_Size - j - 1), ePlayerColor.White);
                    }
                    else
                    {
                        BoardSquares[i, j] = new BoardSquare(new Location(i, j));
                        BoardSquares[i_Size - i - 1, i_Size - j - 1] = new BoardSquare(new Location(i_Size - i - 1, i_Size - j - 1));
                    }
                }
            }

            for (int i = 0; i < i_Size; i++)
            {
                BoardSquares[NumberOfCheckersLine, i]     = new BoardSquare(new Location(NumberOfCheckersLine, i));
                BoardSquares[NumberOfCheckersLine + 1, i] = new BoardSquare(new Location(NumberOfCheckersLine + 1, i));
            }

            return(BoardSquares);
        }
Exemple #9
0
 public ChessboardItem(BoardSquare boardSquare, Player?player, Piece?piece, CellColor color)
 {
     this.boardSquare = boardSquare;
     this.player      = player;
     this.piece       = piece;
     this.color       = color;
 }
Exemple #10
0
        }//close CheckAnyJump

        /// <summary>
        /// makes the piece jump if there is a valid square to jump to
        /// </summary>
        /// <param name="enemyRow">row of location of enenmy</param>
        /// <param name="targetRow">row of location to jump to</param>
        /// <param name="enemyCol">column of location of enenmy</param>
        /// <param name="targetCol">column of location to jump to</param>
        /// <param name="current">current locaiton of piece</param>
        /// <param name="enemy">color of enemy</param>
        /// <param name="jumpMore">result of CheckAnyJump to find any more valid jumps</param>
        /// <returns></returns>
        private bool MakeJump(int enemyRow, int targetRow, int enemyCol, int targetCol,
                              BoardSquare current, SquareColor enemy, out bool jumpMore)
        {
            if (enemyRow < 1 || targetRow < 1 || enemyCol < 1 || targetCol < 1 ||
                enemyRow > 8 || targetRow > 8 || enemyCol > 8 || targetCol > 8)
            {
                jumpMore = false;
                return(false);
            }
            BoardSquare targetTemp;
            BoardSquare enemyTemp;

            if (CheckCapture(_board[enemyRow], enemyCol, enemy, out enemyTemp) &&
                CheckCapture(_board[targetRow], targetCol, SquareColor.None, out targetTemp))
            {
                if (enemyTemp.Color == SquareColor.Red)
                {
                    _redCount--;
                }
                else
                {
                    _blackCount--;
                }
                enemyTemp.Color = SquareColor.None;
                targetTemp.King = current.King;
                jumpMore        = (CheckAnyJump(targetTemp, enemy));
                return(true);
            }
            jumpMore = false;
            return(false);
        }// close MakeJump
Exemple #11
0
 public void GivenAGoUsesABonusSquare_ThenGoWordContainsTheBonusSquare()
 {
     GivenBonusTile(BoardSquare.DoubleLetterSquare(), 3, 7);
     GivenPlayerHorizontalGo("BONUS", 3, 7);
     WhenFindWords();
     foundWords.First().GoLetters.First().LetterBonus.ShouldBe(2);
 }
Exemple #12
0
        /// <summary>
        /// builds the game board using _board dictionary
        /// and each row is a linked list
        /// </summary>
        private void CreateBoard()
        {
            _board = new Dictionary <int, LinkedListCell <BoardSquare> >();
            for (int i = 1; i <= 8; i++)
            {
                _board[i] = null;


                for (int j = 1; j <= 8; j++)
                {
                    BoardSquare create = new BoardSquare(i, j);
                    create.King = false;

                    if (i < 4 && j % 2 != i % 2)
                    {
                        create.Color = SquareColor.Red;
                        _redCount++;
                    }
                    else if (i > 5 && j % 2 != i % 2)
                    {
                        create.Color = SquareColor.Black;
                        _blackCount++;
                    }
                    else
                    {
                        create.Color = SquareColor.None;
                    }

                    LinkedListCell <BoardSquare> temp = new LinkedListCell <BoardSquare>();
                    temp.Data = create;
                    temp.Next = _board[i];
                    _board[i] = temp;
                } //close inner for
            }     //close outer for
        }         //close CreateBoard
Exemple #13
0
    public BoardSquare SetupNext()
    {
        BoardSquare blockSq, nextSq, sideNextSq;
        int         r = squareData.row + dirY;
        int         c = squareData.col + dirX;

        next = null;

        if ((!squareData.reversal && r < GameManager.instance.reverseBoundary ||
             squareData.reversal && r >= GameManager.instance.reverseBoundary) &&
            c >= 0 && c < GameDatabase.instance.playBoardCol)
        {
            nextSq = GameManager.instance.board[r, c];
            if (!nextSq.squareData.disused && nextSq.entity == null)
            {
                next = nextSq;
            }
            else
            {
                int sideCol = squareData.col - 1;

                sideCol = squareData.col;
                for (int i = 0; i < 2; i++)
                {
                    if (0 <= sideCol && sideCol < GameDatabase.instance.playBoardCol)
                    {
                        blockSq    = GameManager.instance.board[squareData.row, sideCol];
                        sideNextSq = GameManager.instance.board[r, sideCol];
                        if (!sideNextSq.squareData.disused && sideNextSq.entity == null && blockSq.squareData.disused)
                        {
                            next = sideNextSq;
                            break;
                        }
                    }

                    sideCol = squareData.col + 1;
                }

//				if(sideCol >= 0)
//				{
//					blockSq = GameManager.instance.board[squareData.row, sideCol];
//					sideNextSq = GameManager.instance.board[r, sideCol];
//					if(!sideNextSq.squareData.disused && sideNextSq.entity == null && blockSq.squareData.disused)
//						next = sideNextSq;
//				}
//
//				sideCol = squareData.col+1;
//
//				if(next == null && sideCol < GameDatabase.instance.playBoardCol)
//				{
//					blockSq = GameManager.instance.board[squareData.row, sideCol];
//					sideNextSq = GameManager.instance.board[r, sideCol];
//					if(!sideNextSq.squareData.disused && sideNextSq.entity == null && blockSq.squareData.disused)
//						next = sideNextSq;
//				}
            }
        }

        return(next);
    }
Exemple #14
0
        private static void PawnMove(ChessPiece piece, BoardSquare targetSquare, ObservableCollection <IBoardItem> items)
        {
            // Promotion
            switch (piece.Color)
            {
            case PieceColor.Black:
                if (piece.Rank == 1)
                {
                    piece.Piece = PieceType.Queen;
                }
                break;

            case PieceColor.White:
                if (piece.Rank == 8)
                {
                    piece.Piece = PieceType.Queen;
                }
                break;
            }
            // En passant
            if (piece.File != targetSquare.File)
            {
                var opponentPawn = items.OfType <ChessPiece>().Where(p => p.Color != piece.Color &&
                                                                     p.Piece == PieceType.Pawn && p.Rank == piece.Rank && p.File == targetSquare.File).FirstOrDefault();

                items.Remove(opponentPawn);
            }

            Move(piece, targetSquare);
        }
Exemple #15
0
 public static void DestroyPooling(BoardSquare bs)
 {
     if (bs != null && bs.gameObject != null)
     {
         Destroy(bs.gameObject);
     }
 }
Exemple #16
0
        public void ChangeSetSquareName()
        {
            BoardSquare boardSquare = new BoardSquare();

            boardSquare.Name = "Marvin Gardens";
            Assert.AreEqual("Marvin Gardens", boardSquare.Name);
        }
Exemple #17
0
        private async void GetQuestion()
        {
            int[]       position    = gameViewModel.game.WhosTurnIsIt.Position;
            BoardSquare boardSquare = boardSquares.Where(x => x.GridRow == position[0] && x.GridColumn == position[1]).First();
            string      difficulty  = "easy";

            resultObject = await gameViewModel.CreateQuestion(boardSquare.Category, difficulty);

            string[] answers = new string[4] {
                resultObject.Results[0].CorrectAnswer,
                resultObject.Results[0].IncorrectAnswers[0],
                resultObject.Results[0].IncorrectAnswers[1],
                resultObject.Results[0].IncorrectAnswers[2]
            };
            answers = RandomizeStrings(answers);
            QuestionText.Visibility = Visibility.Visible;
            Answer1.Visibility      = Visibility.Visible;
            Answer2.Visibility      = Visibility.Visible;
            Answer3.Visibility      = Visibility.Visible;
            Answer4.Visibility      = Visibility.Visible;

            QuestionText.Text = resultObject.Results[0].Question;
            Answer1.Content   = answers[0];
            Answer2.Content   = answers[1];
            Answer3.Content   = answers[2];
            Answer4.Content   = answers[3];
        }
Exemple #18
0
	// Use this for initialization
	void Awake ()
	{
		GameObject global = GameObject.Find ("GlobalObject"); 
		if (global != null) {
			globalObj = global.GetComponent<GlobalObject> ();
		}
		if (globalObj != null) {
			switch (globalObj.boardSize) {
			case 0:
				boardSize = 5;
				break;
			case 1:
				boardSize = 7;
				break;
			case 2:
				boardSize = 9;
				break;
			}
		}

		board = new BoardSquare[boardSize + 2, boardSize + 2]; // Add 2 lanes for the outside walkway
		for (int i = 0; i < boardSize + 2; i++) {
			for (int j = 0; j < boardSize + 2; j++) {
				board [i, j] = new BoardSquare ();

			}
		}
		maxBlocks = boardSize * boardSize; 
	}
Exemple #19
0
        private void PlaceCharacters()
        {
            // TODO
            Log.Info("Placing characters");
            int x = 16;
            int y = 9;

            foreach (var player in GameFlowData.Get().GetPlayers())
            {
                //UnityUtils.DumpGameObject(player);

                ActorData actorData = player.GetComponent <ActorData>();
                var       atsd      = actorData.TeamSensitiveData_authority;
                if (atsd == null)
                {
                    continue;
                }

                BoardSquare start     = Board.Get().GetSquare(x++, y);
                GridPosProp startProp = GridPosProp.FromGridPos(start.GetGridPosition());

                atsd.CallRpcMovement(GameEventManager.EventType.Invalid,
                                     startProp, startProp,
                                     null, ActorData.MovementType.Teleport, false, false);

                actorData.ServerLastKnownPosSquare = start;
                actorData.InitialMoveStartSquare   = start;
                actorData.MoveFromBoardSquare      = start;
                Log.Info($"Placing {actorData.DisplayName} at {startProp.m_x}, {startProp.m_y}");  // PATCH internal -> public ActorData.DisplayName
            }
            Log.Info("Done placing characters");
        }
Exemple #20
0
            public void BasicTests()
            {
                BoardSquareChecker callback = (int file, int rank, bool expected) =>
                {
                    Trace.WriteLine(String.Format("Verifying BoardSquare[{0}:{1}] is {2}", file, rank, expected));
                    Assert.IsTrue(BoardSquare.IsValid(file, rank) == expected);
                };

                // ChessBoard.BoardSquare.IsValid is a static helper that takes
                // ints rather than PieceFiles as those objects must be valid.
                // IsValid helps with offsets to locations that may be invalid
                // (and thus you can't construct a PieceFile)
                // There are only 64 valid squares, check them all
                for (int fileIndex = 1; fileIndex <= 8; fileIndex++)
                {
                    for (int rankIndex = 1; rankIndex <= 8; rankIndex++)
                    {
                        callback(fileIndex, rankIndex, true);
                    }
                }

                // Now try some invalid ones
                callback(0, 0, false);
                callback(-1, -20, false);
                callback(-1, 8, false);
                callback(1, 9, false);
                callback(9, 8, false);
            }
Exemple #21
0
 /// <summary>
 /// Creates a new instance of <see cref="UIFelliSquare"/>.
 /// </summary>
 /// <param name="name">The name given to the element.
 /// This is basically an ID.</param>
 /// <param name="position">The anchor position of this element.</param>
 /// <param name="square">The game's square.</param>
 /// <param name="colorBg">The background color of the element.</param>
 /// <param name="colorFg">The foreground color of the element.</param>
 /// <param name="colorHoverBg">The background color of the element
 /// when hovered.</param>
 public UIFelliSquare(string name, UIPosition position, BoardSquare square,
                      ConsoleColor colorBg      = UISettings.ColorBoardSquareBg,
                      ConsoleColor colorFg      = UISettings.ColorBoardSquareFg,
                      ConsoleColor colorHoverBg = UISettings.ColorBoardSquareHoverBg)
     : base(name, position, colorBg, colorFg, colorHoverBg)
 {
     this.Square = square;
 }
Exemple #22
0
        private static BoardSquare[] GetRookInitialSquares(int column)
        {
            var result = new BoardSquare[2];

            result[(int)Player.Black] = new BoardSquare(BlackInitialRow, column);;
            result[(int)Player.White] = new BoardSquare(WhiteInitialRow, column);
            return(result);
        }
Exemple #23
0
        public void BoardSquare_NoShip_ShouldHaveMissedStateAfterShot()
        {
            var boardSquare = new BoardSquare();

            boardSquare.TakeTheShot();

            Assert.Equal(((char)BoardSquareState.Missed).ToString(), boardSquare.GetCurrentStateAsString());
        }
Exemple #24
0
        public void SetValuesFromBoardSquare(BoardSquare targetSquare, Vector3 currentWorldPos)
        {
            var dir = targetSquare.ToVector3() - currentWorldPos;

            dir.Y = 0.0f;
            Vector3.Normalize(dir);
            SetPosAndDir(targetSquare.GridPos, targetSquare.ToVector3(), dir);
        }
Exemple #25
0
 public void GivenAGoUsesABonusSquare_ThenSideWordContainsTheBonusSquare()
 {
     GivenBonusTile(BoardSquare.DoubleWordSquare(), 4, 7);
     GivenBoardTile('N', 4, 8);
     GivenPlayerHorizontalGo("BONUS", 3, 7);
     WhenFindWords();
     foundWords.First(go => go.Word == "ON").GoLetters.First().WordBonus.ShouldBe(2);
 }
Exemple #26
0
        public bool IsCanApplyTo(BoardSquare originSquare)
        {
            var destRow    = originSquare.Row + DeltaRow;
            var destColumn = originSquare.Column + DeltaColumn;

            return(destRow >= 0 && destRow < Board.Board.RowCount &&
                   destColumn >= 0 && destColumn < Board.Board.ColumnCount);
        }
Exemple #27
0
        public void copy_status(BoardSquare copy_from)
        {
            beer_can_present = copy_from.beer_can_present;
            bender_present   = copy_from.bender_present;
            visited_state    = copy_from.visited_state;

            walls = copy_from.walls;
        }
Exemple #28
0
 void GivenBonusTile(BoardSquare square, int x, int y)
 {
     gridModel.GetBoardSquare(x, y).Returns(square);
     gridModel.GetGoLetter(x, y).Returns(new GoLetter()
     {
         LetterBonus = square.LetterBonus,
         WordBonus   = square.WordBonus
     });
 }
Exemple #29
0
 private void MovePiece(BoardSquare target)
 {
     SelectedPiece.GetSquare().SetPiece(null);
     SelectedPiece.SetSquare(target);
     SelectedPiece.MatchPosition();
     SelectedPiece.hasMoved = true;
     clearOldCoverStatus();
     DeselectPiece();
 }
Exemple #30
0
    private void CheckBoardSize()
    {
        // Get the board square size from the dummy board square, to help with tile positioning
        BoardSquare boardSquare = dummyBoardSquareObject.GetComponent <BoardSquare>();

        boardSquareSize = boardSquare.GetSize();

        CheckBoardScale();
    }
Exemple #31
0
        public void AddPieceToBoardSquareTest()
        {
            var boardSquare = new BoardSquare();
            var piece       = new MockPiece();

            boardSquare.AddPiece(piece);

            Assert.AreEqual(piece, boardSquare.BoardSquareContent);
        }
Exemple #32
0
    /// <summary>
    /// Check which square the quad copter is closest to. 
    /// </summary>
    /// <param name="copter"></param>
    /// <returns></returns>
    public Vector3 CopterLocation(Obstacle copter)
    {
        float smallest = int.MaxValue;
        BoardSquare bsReturn = new BoardSquare();

        foreach (BoardSquare square in this.GameBoard)
        {
            float value = Vector2.Distance((Vector2)copter.transform.position, square.Position);
            bsReturn = smallest < value ? square : bsReturn;
        }

        return (Vector3)bsReturn.Position;
    }
        /// <summary>
        /// Returns indexes of a position
        /// </summary>
        /// <param name="square">Square on the board</param>
        /// <param name="position">Position inside squar</param>
        /// <param name="index1">Index</param>
        /// <param name="index2">Index</param>
        public static void GetIndexes(BoardSquare square, SquarePosition position, ref int index1, ref int index2)
        {
            index1 = -1;
            index2 = -1;

            for (int i = 0; i <= 6; i++)
            {
                for (int j = 0; j <= 6; j++)
                {
                    if (GetSquare(i, j) == square && GetPosition(i, j) == position)
                    {
                        index1 = i;
                        index2 = j;

                        return;
                    }
                }
            }
        }
Exemple #34
0
    // Setup Game Board
    public ScoreBoard(Transform transform, GameObject[] obstacles)
    {
        Obstacles = new List<GameObject>();
        Obstacles.AddRange(obstacles);
        int x = (int)(transform.localScale.x * 10);
        int z = (int)(transform.localScale.z * 10);
        Vector2 offset = new Vector2(transform.position.x - x * 0.5f, transform.position.z - z * 0.5f);
        GameBoard = new BoardSquare[x, z];

        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < z; j++)
            {
                GameBoard[i, j] = new BoardSquare(offset + new Vector2(i, j), 1);
            }
        }

        GameBoardScore = GameBoard.Length;
    }
Exemple #35
0
 private void SetSquares(BoardSquare[,] squares, TerritoryFn whatBelongsToWho)
 {
     TerritoryOf = whatBelongsToWho;
     Squares = squares;
     foreach (BoardSquare square in Squares)
     square.AdjacentSquaresInit ();
 }
Exemple #36
0
        /// <summary>
        /// Help function for PossibleMoves
        /// </summary>
        /// <param name="playstones">Actual board</param>
        /// <param name="square">Board square</param>
        /// <param name="pos">Position inside the square</param>
        private static void CheckPositionForMove(PlaystoneState[,] playstones, BoardSquare square,
            SquarePosition pos)
        {
            int i = 0, j = 0;

            ModelHelpFunctions.GetIndexes(square, pos, ref i, ref j);
            if (playstones[i, j] == PlaystoneState.Neutral)
                playstones[i, j] = PlaystoneState.Selectable;
        }
 public void AddSquare(BoardSquare boardSquare)
 {
     if (boardSquare != null)
         AddChild(boardSquare);
 }
Exemple #38
0
 public void setMoves(BoardSquare[,] currentMoves)
 {
     mBoardSquares = currentMoves;
 }
 public void AddSquare(BoardSquare square)
 {
     _squares.Add(square);
 }
 private static BoardSquare CreateSquare(int tile, int row, int column)
 {
     var square = new BoardSquare(tile); //BoardSquare object inherits button - see BoardSquare.cs
     square.Text = tile.ToString();
     square.Size = new System.Drawing.Size(35, 35);
     square.Location = new Point(column*35, row*35);
     square.Enabled = false;
     return square;
 }
Exemple #41
0
    //TODO: If gamemanager.turn = me, enable aimer.  Else, disable aimer.
    public void playerClickedSquare(BoardSquare clickedSquare)
    {
        //Highlight valid moves
        if (!heldBoardPiece)
        {
            //If we clicked an empty square, forget it.
            if(clickedSquare.gamePiece == null)
            {
                return;
            }

            heldBoardPiece = clickedSquare.gamePiece;
            List<BoardMove> validMoves = gameManager.gameRules.getValidMoveForPiece(board, heldBoardPiece, this);

            if (validMoves.Count > 0)
            {
                //heldBoardPiecePosition = boardSquare.positionOnBoard;
                heldBoardPiece = clickedSquare.gamePiece;

                //Show valid moves
                foreach (BoardMove validMove in validMoves)
                {
                    board.getSquare(validMove.destination).addHighlight("GAMEMANAGER_VALID_MOVE", new Color(0, 0.5f, 0));
                }
            }
            else
            {
                heldBoardPiece = null;
                //TODO: Play some annoying sound
            }
        }
        else //Player is currently holding a piece and is trying to make a move.
        {
            //Cancle the move
            if (clickedSquare.boardPosition == heldBoardPiece.boardPosition)
            {
                gameManager.board.clearHighlights("GAMEMANAGER_VALID_MOVE");
                heldBoardPiece = null;
                return;
            }

            bool validMove = false;

            //TODO: Issues here!

            // Check if the clicked square is a valid move.
            // Because I'm too lazy to figure out how to filter this with a predicate.
            // Probably a good thing overall, anyway.
            foreach(BoardMove targetMove in gameManager.gameRules.getValidMoveForPiece(board, heldBoardPiece, this))
            {
                if ((clickedSquare.boardPosition.vertical == targetMove.destination.vertical)
                    && (clickedSquare.boardPosition.horizontal == targetMove.destination.horizontal))
                {
                    validMove = true;
                    playerPickedMove(targetMove);
                    break;
                }
            }

            if(validMove)
            {
                board.clearAllHighlights();
                Debug.Log("Player made a move! Time to call the game manager.");
                //gameManager.playerChoseValidSquare(heldBoardPiece, clickedSquare.boardPosition);
                heldBoardPiece = null;
            }
            else
            {
                //Play an annoying sound
            }
        }
    }
Exemple #42
0
        public bool PlacePiece(Player owner, PieceType type, BoardSquare target)
        {
            Piece pieceToPlace = new Piece (this, owner, type);

            if (TerritoryOf (target) != pieceToPlace.Owner)
            {
            return false;
            }
            else if (Pieces.ContainsKey (target))
            {
            return false;
            }
            else if (target.Type != BoardSquareType.NORMAL)
            {
            return false;
            }
            else
            {
            pieceToPlace.Place (target);
            ActualPieces.Add (pieceToPlace);
            Messenger<GameToken>.Invoke ("piece.placed", GameToken.FromPiece (pieceToPlace));
            return true;
            }
        }
Exemple #43
0
        private static Board CreateFromData(string[] boardLines)
        {
            Board board = new Board ();

            BoardSquare[,] squares = new BoardSquare[boardLines [0].Length, boardLines.Length];

            for (int y = 0; y < boardLines.Length; y++)
            {
            for (int x = 0; x < boardLines[y].Length; x++)
            {
                char incoming = boardLines [y] [x];

                if (incoming.Equals ('_'))
                {
                    squares [x, y] = new BoardSquare (board, BoardSquareType.EDGE, new Coords (){x = x, y = y});
                }
                else if (incoming.Equals ('='))
                {
                    squares [x, y] = new BoardSquare (board, BoardSquareType.RAIL, new Coords (){x = x, y = y});
                }
                else if (incoming.Equals ('#'))
                {
                    squares [x, y] = new BoardSquare (board, BoardSquareType.NORMAL, new Coords (){x = x, y = y});
                }
                else
                {
                    throw new NotSupportedException ("Board Map includes tile that was not recognised.");
                }
            }
            }

            board.SetSquares (squares,
                (square) =>
            {
            if (square.Pos.x < squares.GetLength (0) / 2)
            {
                return Player.P1;
            }
            else
            {
                return Player.P2;
            }
            }
            );
            return board;
        }
Exemple #44
0
 /// <summary>
 /// Determines the distance between two neighboring squares. 
 /// </summary>
 /// <returns></returns>
 public float DistanceToNeighbor(BoardSquare other)
 {
     return Vector2.Distance(Position, other.Position);
 }
Exemple #45
0
        public static void SetupBoardPool(Board template)
        {
            if (Pool != null)
            {
            return;
            }
            Pool = new Pooling.Pool<Board> (AMT_BOARDS_NEEDED_PER_SEARCH * Environment.ProcessorCount, pool => {
            Board newBoard = new Board ();

            BoardSquare[,] squares = new BoardSquare[template.Width, template.Height];
            for (int y = 0; y < template.Height; y++)
            {
                for (int x = 0; x < template.Width; x++)
                {
                    squares [x, y] = new BoardSquare (newBoard, template.Squares [x, y].Type, new Coords () { x = x, y = y });
                }
            }
            newBoard.SetSquares (squares, template.TerritoryOf);
            return newBoard;
            },
             Pooling.LoadingMode.Eager,
             Pooling.AccessMode.FIFO);
        }