コード例 #1
0
    public void moveSpaces(int roll)
    {
        int newPos = currentPosition + roll;

        if (newPos > 15)
        {
            moveBlock(newPos % 16);
            GameController.endGame(newPos);
            return;
        }
        BoardSpace landingSpace = Board.spaces [newPos];

        if (landingSpace.getBonus() != 0)
        {
            int playerOwns = Board.bonusSquaresOwned[newPos];
            GameController.players[playerOwns].alterFunds(2);
            newPos += landingSpace.getBonus();
        }


        if (newPos > 15)
        {
            GameController.getResults(newPos);
            GameController.gameEndFlag = true;
            return;
        }
        moveBlock(newPos);
    }
コード例 #2
0
 public Board(BoardSpace[] spaceCollection)
 {
     foreach (BoardSpace space in spaceCollection) {
         int[] indexArray = getIndex(space);
         spaces[indexArray[0],indexArray[1]] = space;
     }
 }
コード例 #3
0
    int EvaluationFunction(BoardSpace[][] currentBoard, BoardSpace color, bool isGameCompleted)
    {
        int totalDifference = 0;

        foreach (BoardSpace[] row in currentBoard)
        {
            foreach (BoardSpace space in row)
            {
                if (space == color)
                {
                    totalDifference++;
                }
                else if (space != BoardSpace.EMPTY)
                {
                    totalDifference--;
                }
            }
        }
        if (isGameCompleted)
        {
            if (totalDifference > 0)
            {
                return(currentBoard.Length * currentBoard[0].Length);
            }
            if (totalDifference < 0)
            {
                return(currentBoard.Length * currentBoard[0].Length * -1);
            }
        }
        return(BoardScript.GetValidMoves(currentBoard, color == BoardSpace.BLACK ? 0u : 1u).Count);
    }
コード例 #4
0
    public PieceMove GetNextMove(Vector3 StartLoc, BoardPiece cat, BoardSpace moveSpace, Board.Direction direction)
    {
        //movesIndex += 1;
        PieceMove move = Moves[movesIndex];

        if (move.GetMyType() == "Walk" && Board.GetBoardDistance(move.moveSpace.GetSpaceByDirection(direction).GetCenterPoint(), cat.transform.position) > 0.1f)
        {
            moveSpace = moveSpace.GetSpaceByDirection(direction);
            Debug.Log("flipped " + moveSpace.name + " " + move.moveSpace.name);

            Board.Direction flippedDir = Board.FlipDirection(direction);
            cat.pieceDirection = flippedDir;
            GetMoveFlipped(flippedDir, moveSpace);
            return(move);
        }
        else if (movesIndex + 1 >= Moves.Count)
        {
            isActive = false;
            return(null);
        }
        else
        {
            movesIndex += 1;
            initializeMove(StartLoc, cat, moveSpace, direction, movesIndex);
            return(GetMove());
        }
    }
コード例 #5
0
ファイル: NegaMaxAI.cs プロジェクト: hihihahahu/Othello
    int NegaMax(BoardSpace[][] node, int depth, int alpha, int beta, BoardSpace color)
    {
        bool completed = IsGameCompleted(node);  //call evaluation function recursively

        if (depth == 0 || completed)
        {
            int evaluation = EvaluationFunction(node, color, completed);


            return(color == this.color ? evaluation : -evaluation);
        }
        BoardSpace[][][] children = GetChildrenNodes(node, color == BoardSpace.BLACK ? BoardSpace.WHITE : BoardSpace.BLACK);
        if (children.Length == 0)
        {
            return(-NegaMax(node, depth, -beta, -alpha, color == BoardSpace.BLACK ? BoardSpace.WHITE : BoardSpace.BLACK));
        }

        int value = int.MinValue;

        foreach (BoardSpace[][] child in children)
        {
            value = Mathf.Max(value, -NegaMax(child, depth - 1, -beta, -alpha, color == BoardSpace.BLACK ? BoardSpace.WHITE : BoardSpace.BLACK));
            alpha = Mathf.Max(alpha, value);
            if (alpha >= beta)
            {
                break;
            }
        }
        return(value);
    }
コード例 #6
0
ファイル: NegaMaxAI.cs プロジェクト: hihihahahu/Othello
    BoardSpace[][] CopyBoard(BoardSpace[][] board)
    {
        BoardSpace[][] copy = new BoardSpace[board.Length][];
        for (int i = 0; i < board.Length; ++i)
        {
            copy[i] = new BoardSpace[board[i].Length];
            for (int j = 0; j < board[i].Length; ++j)
            {
                switch (board[i][j])
                {
                case (BoardSpace.BLACK):
                    copy[i][j] = BoardSpace.BLACK;
                    break;

                case (BoardSpace.WHITE):
                    copy[i][j] = BoardSpace.WHITE;
                    break;

                default:
                    copy[i][j] = BoardSpace.EMPTY;
                    break;
                }
            }
        }
        return(copy);
    }
コード例 #7
0
ファイル: SmartBehavior.cs プロジェクト: ConcededGore/Othello
    private void testCheckSameColor()
    {
        BoardSpace[][] tempBoard = new BoardSpace[8][];

        tempBoard = getEmptyBoard();

        // Basic test if true
        for (int i = 0; i < 8; i++)
        {
            tempBoard[i][0] = BoardSpace.BLACK;
        }
        tempBoard[3][0] = BoardSpace.EMPTY;
        Debug.Log("test 1 should be true, is: " + CheckSameColor(tempBoard, new KeyValuePair <int, int>(3, 0), BoardSpace.BLACK));

        tempBoard = getEmptyBoard();

        // Basic test if false (empty)
        Debug.Log("test 2 should be false, is " + CheckSameColor(tempBoard, new KeyValuePair <int, int>(3, 0), BoardSpace.BLACK));

        tempBoard = getEmptyBoard();

        // Basic test if false (almost full)
        for (int i = 0; i < 8; i++)
        {
            tempBoard[i][0] = BoardSpace.BLACK;
        }
        tempBoard[4][0] = BoardSpace.WHITE;
        Debug.Log("test 3 should be false, is " + CheckSameColor(tempBoard, new KeyValuePair <int, int>(3, 0), BoardSpace.BLACK));

        tempBoard = getEmptyBoard();

        // Basic test if true (corner)
        for (int i = 0; i < 8; i++)
        {
            tempBoard[i][0] = BoardSpace.BLACK;
        }
        for (int i = 0; i < 8; i++)
        {
            tempBoard[0][i] = BoardSpace.BLACK;
        }
        tempBoard[0][0] = BoardSpace.EMPTY;

        Debug.Log("Test 4 should be true, is: " + CheckSameColor(tempBoard, new KeyValuePair <int, int>(0, 0), BoardSpace.BLACK));

        tempBoard = getEmptyBoard();

        // Basic test if true (one edge of corner)
        for (int i = 0; i < 8; i++)
        {
            tempBoard[i][0] = BoardSpace.BLACK;
        }
        for (int i = 0; i < 8; i++)
        {
            tempBoard[0][i] = BoardSpace.BLACK;
        }
        tempBoard[0][0] = BoardSpace.EMPTY;
        tempBoard[0][2] = BoardSpace.WHITE;

        Debug.Log("Test 5 should be true, is: " + CheckSameColor(tempBoard, new KeyValuePair <int, int>(0, 0), BoardSpace.BLACK));
    }
コード例 #8
0
    public BoardSpace[][] createNewBoard(BoardSpace[][] board, KeyValuePair <int, int> move, bool isBlack)
    {
        BoardSpace[][] newBoard = new BoardSpace[8][];
        //Copy board
        for (int i = 0; i < 8; i++)
        {
            newBoard[i] = new BoardSpace[8];
            for (int j = 0; j < 8; j++)
            {
                newBoard[i][j] = board[i][j];
            }
        }

        newBoard[move.Key][move.Value] = isBlack ? BoardSpace.BLACK : BoardSpace.WHITE;

        //Update Moves
        List <KeyValuePair <int, int> > changedSpots = BoardScript.GetPointsChangedFromMove(newBoard, isBlack ? ((uint)2) : ((uint)1), move.Value, move.Key);

        foreach (KeyValuePair <int, int> change in changedSpots)
        {
            newBoard[change.Key][change.Value] = isBlack ? BoardSpace.BLACK : BoardSpace.WHITE;
        }

        return(newBoard);
    }
コード例 #9
0
ファイル: Board.cs プロジェクト: crassSandwich/wgj84
    public BoardPiece TryGetPiece(BoardSpace space)
    {
        BoardPiece p;

        state.TryGetValue(space, out p);
        return(p);
    }
コード例 #10
0
    public void MoveSelected(BoardSpace spaceObj)
    {
        canSelect = false;
        SetSelectable(false);
        SelectedPiece.transform.position = spaceObj.transform.position;

        if (spaceObj.isKingSpace)
        {
            SelectedPiece.GetComponent <Piece>().IsKing = true;
        }

        if (spaceObj.JumpedPiece != null)
        {
            Capture(spaceObj.JumpedPiece);

            if (_inactivePlayer.pieces.Count == 0)
            {
                //implement game over
                canSelect = false;
                HideSpaces();

                GameInfo.text = "Game Over : " + _activePlayer.pieces[0].tag + " Wins!";
            }
            else
            {
                jumpsOnly = true;
                ShowSpaces(SelectedPiece.transform.position);
            }
        }
        else
        {
            HideSpaces();
        }
    }
コード例 #11
0
    // Attempt to add the given space to the current dot link
    public void AddSpace(BoardSpace space)
    {
        // already connected, don't allow
        if (ConnectionExists(space))
        {
            return;
        }

        previousConnected = lastConnected;
        lastConnected     = space;

        // the link's type matches the first dot added
        if (IsEmpty())
        {
            dotType = space.GetCurrentDot().GetDotType();
        }

        // add the dot
        currentConnectedSpaces.Add(space);
        space.GetCurrentDot().Select();

        // connect last spaces with the line
        if (currentConnectedSpaces.Count >= 2)
        {
            previousConnected.Connect(lastConnected);
        }
    }
コード例 #12
0
    private void AddSegmentSpaceRecursively(BeamSegment _segment, int exitSide)
    {
        // Do we have too many segments? Okay, stop; we're probably caught in an infinite-Beam Portal mirroring situation.
        if (NumSegments > 10)
        {
            return;
        }
        // Are we not allowed to EXIT this space? Then stop here.
        if (!BoardUtils.CanBeamExitSpace(GetSpace(_segment.LastColRow), exitSide))
        {
            return;
        }
        // What space will we add it to?
        TranslationInfo ti             = BoardUtils.GetTranslationInfo(mySource.BoardRef, _segment.LastColRow, exitSide);
        BoardSpace      spaceToAddBeam = BoardUtils.GetSpace(BoardRef, ti.to);
        // If we can't ENTER the next space, then stop. :)
        int nextSideIn = MathUtils.GetSide(ti.dirIn);

        if (!BoardUtils.CanBeamEnterSpace(spaceToAddBeam, nextSideIn))
        {
            return;
        }
        // Otherwise, add this space to the segment!
        _segment.AddSpace(spaceToAddBeam);
        // How is the beam exiting??
        int endSideExiting = spaceToAddBeam.GetSideBeamExits(nextSideIn);          // keep updaing endSideExiting (until we hit the end).

        // Otherwise, keep going! Add again!
        AddSegmentSpaceRecursively(_segment, endSideExiting);
    }
コード例 #13
0
    private void setSpaceElevation(BoardSpace space, BoardSpace addedSpace)
    {
        BoardSpace.BoardSpaceElevations elevation = BoardSpace.BoardSpaceElevations.Level;
        if (addedSpace.y > space.y)
        {
            elevation = BoardSpace.BoardSpaceElevations.Up;
        }
        else if (addedSpace.y < space.y)
        {
            elevation = BoardSpace.BoardSpaceElevations.Down;
        }

        if (space.NegX == addedSpace)
        {
            space.NegXElev = elevation;
        }
        if (space.NegZ == addedSpace)
        {
            space.NegZElev = elevation;
        }
        if (space.PosX == addedSpace)
        {
            space.PosXElev = elevation;
        }
        if (space.PosZ == addedSpace)
        {
            space.PosZElev = elevation;
        }
    }
コード例 #14
0
    private GameBoard(GameBoard other)
    {
        this.board = new BoardSpace[GRIDSIZE, GRIDSIZE];
        bool faceup;

        for (int y = 0; y < GRIDSIZE; y++)
        {
            for (int x = 0; x < GRIDSIZE; x++)
            {
                faceup      = (x + y) % 2 == 0;
                board[x, y] = new BoardSpace(x, y, faceup);
                if (other.board[x, y].getCard() != null)
                {
                    board[x, y].setCard(other.board[x, y].getCard().CopyCard());
                }
            }
        }
        int max = GRIDSIZE;

        player1KnownCards = new bool[max][];
        player2KnownCards = new bool[max][];

        for (int x = 0; x < max; x++)
        {
            player1KnownCards[x] = new bool[max];
            player2KnownCards[x] = new bool[max];
            for (int y = 0; y < max; y++)
            {
                player1KnownCards[x][y] = other.player1KnownCards[x][y];
                player2KnownCards[x][y] = other.player2KnownCards[x][y];
            }
        }
    }
コード例 #15
0
ファイル: BoardScript.cs プロジェクト: AlbMej/Game-AI-Hw-8
    private void InitBoard()   //set up board
    {
        board            = new BoardSpace[8][];
        boardGameObjects = new GameObject[8][];
        turnNumber       = 0;
        gameStarted      = false;
        for (int i = 0; i < 8; ++i)
        {
            board[i]            = new BoardSpace[8];
            boardGameObjects[i] = new GameObject[8];
            for (int j = 0; j < 8; ++j)
            {
                board[i][j]            = BoardSpace.EMPTY;
                boardGameObjects[i][j] = null;
            }
        }
        PlacePiece(3, 3);
        PlacePiece(3, 4);
        PlacePiece(4, 4);
        PlacePiece(4, 3);
        gameStarted = true;
        List <KeyValuePair <int, int> > moves = GetValidMoves(board, turnNumber);

        currentValidMoves = moves;
    }
コード例 #16
0
ファイル: DebugHelper.cs プロジェクト: bitDecayGames/fireport
        public static GameState DebugGameState()
        {
            var gs = new GameState();

            gs.Turn           = 3;
            gs.Winner         = -1;
            gs.IsGameFinished = false;
            gs.BoardWidth     = 7;
            gs.BoardHeight    = 4;
            gs.BoardSpaces    = new List <BoardSpace>();
            for (int i = 0; i < gs.BoardWidth * gs.BoardHeight; i++)
            {
                var bs = new BoardSpace();
                bs.ID = getId(gs);
                gs.BoardSpaces.Add(bs);
            }
            gs.Players = new List <PlayerState>();
            for (int i = 0; i < 4; i++)
            {
                var ps = new PlayerState();
                ps.ID       = getId(gs);
                ps.Name     = "Player" + (i + 1);
                ps.Location = (i + 1) * 2;
                ps.Facing   = i;
                ps.Deck     = new List <CardState>();
                ps.Discard  = new List <CardState>();
                ps.Hand     = new List <CardState>();
                ps.Health   = 10;
                gs.Players.Add(ps);
            }

            return(gs);
        }
コード例 #17
0
    //Negamax returning a boardspace to move to. Calls abNegamax. currently used.
    public BoardSpace NegaMaxMove(int depth, int player)
    {
        //Initalise maxMove score as a very small number
        int        maxScore = int.MinValue + 1;
        BoardSpace bestMove = null;

        //Iterate through each available space
        foreach (BoardSpace space in placePiece.GetAvailableSpaces(tempBoard))
        {
            //Make move in each space
            placePiece.MakeMove(tempBoard, space, player);

            //temporary value v represents score for each move. 3 - player switches to other player's perspective
            int v = -abNegaMax(depth - 1, 3 - player, int.MinValue + 1, int.MaxValue - 1);

            Debug.Log("Score for player " + player + " move: " + space.x + ", " + space.y + " is: " + v);

            placePiece.UnmakeMove(tempBoard, space);

            //Set maxScore to largest value
            if (v > maxScore)
            {
                maxScore = v;
                bestMove = space;
            }
        }

        Debug.Log("Returning Best Move: " + bestMove.x + ", " + bestMove.y + " with a score of: " + maxScore);
        return(bestMove);
    }
コード例 #18
0
    private void DoNextGenerationStep(List <BoardSpace> activeSpaces)
    {
        int currentIndex = activeSpaces.Count - 1;
        //int currentIndex = Random.Range(0, activeSpaces.Count);
        BoardSpace currentSpace = activeSpaces[currentIndex];

        if (currentSpace.IsFullyInitialized)
        {
            activeSpaces.RemoveAt(currentIndex);
            return;
        }

        Direction  direction   = currentSpace.GetRandomUninitializedDirection();
        Vector2Int coordinates = currentSpace.coordinates + direction.ToCoordinates();

        if (ContainsCoordinates(coordinates))
        {
            BoardSpace neighbour = GetSpace(coordinates);
            if (neighbour == null)
            {
                neighbour = CreateSpace(coordinates);
                CreatePassage(currentSpace, neighbour, direction);
                activeSpaces.Add(neighbour);
            }
            else
            {
                CreateWall(currentSpace, neighbour, direction);
            }
        }
        else
        {
            CreateWall(currentSpace, null, direction);
        }
    }
コード例 #19
0
ファイル: Move.cs プロジェクト: adomaszi/MonopolySourceCode
 public Move(Player player, BoardSpace property, decimal moneyPaid, int numberRolled)
 {
     _player       = player;
     _property     = property;
     _moneyPaid    = moneyPaid;
     _numberRolled = numberRolled;
 }
コード例 #20
0
        private void Promote(BoardSpace space)
        {
            string choice;

            PromotionDialogue dialogue = new PromotionDialogue();

            dialogue.ShowDialog();
            choice = dialogue.Choice;

            int presentColor = space.Piece.Color;

            switch (choice)
            {
            case "queen":
                space.Piece = new Queen(this.boardModel, presentColor);
                break;

            case "knight":
                space.Piece = new Knight(this.boardModel, presentColor);
                break;

            case "rook":
                space.Piece = new Rook(this.boardModel, presentColor);
                break;

            case "bishop":
                space.Piece = new Bishop(this.boardModel, presentColor);
                break;

            case "pawn":
                space.Piece = new Pawn(this.boardModel, presentColor);
                break;
            }
        }
コード例 #21
0
    // ----------------------------------------------------------------
    //  Initialize
    // ----------------------------------------------------------------
    public void Initialize(BoardView _boardView, BoardSpace mySpace)
    {
        this.myBoardView = _boardView;
        int col = mySpace.Col;
        int row = mySpace.Row;

        // Parent me to my boooard!
        GameUtils.ParentAndReset(this.gameObject, _boardView.tf_boardSpaces);
        this.gameObject.name = "BoardSpace_" + col + "," + row;

        // Size/position me right!
        float diameter = _boardView.UnitSize - 1;

        myRectTransform.anchoredPosition = new Vector2(_boardView.BoardToX(col), _boardView.BoardToY(row));
        myRectTransform.sizeDelta        = new Vector2(diameter, diameter);

        // Only show body if I'm playable.
        i_body.enabled = mySpace.IsPlayable;

        // Add walls!
        if (mySpace.IsWall(Sides.T))
        {
            AddWallImage(Sides.T);
        }
        if (mySpace.IsWall(Sides.L))
        {
            AddWallImage(Sides.L);
        }
    }
コード例 #22
0
    public void QueueSpill(BoardSpace spaceToSpill, int xDirection, int zDirection)
    {
        int boardSpaceX = spaceToSpill.colNum;
        int boardSpaceZ = spaceToSpill.rowNum;

        tilesQueuedToSpill = new List <Tile> ();
        int numTilesToMove = spaceToSpill.tileList.Count;

        totalSpillTime = Mathf.Max(totalSpillTime, numTilesToMove * 0.4f);

        juicy.delayTileSpill = 0f;
        juicy.xSpillDir      = xDirection;
        juicy.zSpillDir      = zDirection;
        spaceToSpill.provisionalTileCount = 0;
        spaceQueuedToSpillFrom            = spaceToSpill;
        juicy.PositionStackToSpill(spaceToSpill);
        for (int i = 0; i < numTilesToMove; i++)
        {
            int  index      = numTilesToMove - 1 - i;
            Tile tileToMove = spaceToSpill.tileList [index];
            tilesQueuedToSpill.Add(tileToMove);
            int[] targetCoords = CalculateAdjacentSpace(boardSpaceX, boardSpaceZ, xDirection, zDirection);
            boardSpaceX = targetCoords [0];
            boardSpaceZ = targetCoords [1];
            BoardSpace spaceToSpillOnto = board [boardSpaceX, boardSpaceZ];
            tileToMove.spaceQueuedToSpillOnto = spaceToSpillOnto;
            spaceToSpillOnto.PositionNewTile(tileToMove);
        }
    }
コード例 #23
0
ファイル: BoardSpace.cs プロジェクト: rcornwal/DotsGame
    // Finds adjacent board spaces
    public void CalculateAdjacentSpaces(List <List <BoardSpace> > board)
    {
        BoardSpace left   = null;
        BoardSpace right  = null;
        BoardSpace top    = null;
        BoardSpace bottom = null;

        if (boardIndex.x > 0)
        {
            left = board[boardIndex.x - 1][boardIndex.y];
        }
        if (boardIndex.x < board.Count - 1)
        {
            right = board[boardIndex.x + 1][boardIndex.y];
        }
        if (boardIndex.y > 0)
        {
            bottom = board[boardIndex.x][boardIndex.y - 1];
        }
        if (boardIndex.y < board[0].Count - 1)
        {
            top = board[boardIndex.x][boardIndex.y + 1];
        }
        adjacentSpaces = new AdjacentSpaces(left, right, top, bottom);

        // add dot spawners to the top row
        if (top == null)
        {
            IsTopSpace = true;
            BoardSpaceSpawner boardSpaceSpawner = gameObject.AddComponent <BoardSpaceSpawner>();
            boardSpaceSpawner.SetCoordinateSpace(coordinateSpace);
            boardSpaceSpawner.SetDotManager(dotManager);
            spawner = boardSpaceSpawner;
        }
    }
コード例 #24
0
        public Card GetCardFromSpace(BoardSpace cardSlot)
        {
            Card card;

            switch (cardSlot)
            {
            case BoardSpace.CivilizationCardSlot1:
                card = CardSlot1;
                break;

            case BoardSpace.CivilizationCardSlot2:
                card = CardSlot2;
                break;

            case BoardSpace.CivilizationCardSlot3:
                card = CardSlot3;
                break;

            case BoardSpace.CivilizationCardSlot4:
                card = CardSlot4;
                break;

            default:
                throw new InvalidSpaceForCardsException(cardSlot);
            }
            return(card);
        }
コード例 #25
0
 private void setupBoard()
 {
     for (int i = 0; i < BoardSpaces.Length; i++)
     {
         BoardSpace space = BoardSpaces[i];
         if (i % 5 < 4)
         {
             space.PosX = BoardSpaces[i + 1];
             setSpaceElevation(space, space.PosX);
         }
         if (i % 5 > 0)
         {
             space.NegX = BoardSpaces[i - 1];
             setSpaceElevation(space, space.NegX);
         }
         if ((int)(i / 5) > 0)
         {
             space.NegZ = BoardSpaces[i - 5];
             setSpaceElevation(space, space.NegZ);
         }
         if ((int)(i / 5) < 4)
         {
             space.PosZ = BoardSpaces[i + 5];
             setSpaceElevation(space, space.PosZ);
         }
     }
 }
コード例 #26
0
    IEnumerator Drop()
    {
        bool overlappingDrop = dotsDropping;

        dotsDropping = true;

        // Drop dots column by column
        for (int k = 0; k < boardHeight; k++)
        {
            for (int i = 0; i < boardWidth; i++)
            {
                BoardSpace    curSpace        = BoardArray[i][k];
                DotController curDot          = curSpace.GetCurrentDot();
                bool          alreadyDropping = curDot.IsDropping;
                if (curSpace.IsEmpty || curDot.FlaggedToDrop || curDot.IsDropping)
                {
                    dotsToDrop++;
                    curDot.OnDropComplete += OnDropComplete;
                    curSpace.DropDot(dropTime);
                }
            }

            // offset each row's drop, if its not an overlapping drop call
            if (!overlappingDrop)
            {
                yield return(dropRow);
            }
        }
    }
コード例 #27
0
    // Evaluate function 1, counts number of pieces and heavily weights corners
    public int evaluate(BoardSpace[][] Board, uint turnNumber)
    {
        BoardSpace ourColor = turnNumber % 2 == 0 ? BoardSpace.BLACK : BoardSpace.WHITE;
        int        count    = 0;

        foreach (BoardSpace[] row in Board)
        {
            foreach (BoardSpace space in row)
            {
                if (space == ourColor)
                {
                    count++;
                }
            }
        }
        foreach (BoardSpace[] row in Board)
        {
            foreach (BoardSpace space in row)
            {
                if (space != ourColor && space != BoardSpace.EMPTY)
                {
                    count--;
                }
            }
        }
        if (Board[0][0] == ourColor)
        {
            count += 20;
        }
        if (Board[7][7] == ourColor)
        {
            count += 20;
        }
        if (Board[0][7] == ourColor)
        {
            count += 20;
        }
        if (Board[7][0] == ourColor)
        {
            count += 20;
        }
        if (Board[0][0] != ourColor && Board[0][0] != BoardSpace.EMPTY)
        {
            count -= 20;
        }
        if (Board[7][7] != ourColor && Board[7][7] != BoardSpace.EMPTY)
        {
            count -= 20;
        }
        if (Board[0][7] != ourColor && Board[0][7] != BoardSpace.EMPTY)
        {
            count -= 20;
        }
        if (Board[7][0] != ourColor && Board[7][0] != BoardSpace.EMPTY)
        {
            count -= 20;
        }
        return(count);
    }
コード例 #28
0
    private void CreatePassage(BoardSpace space, BoardSpace otherSpace, Direction direction)
    {
        BoardPassage passage = Instantiate(passagePrefab);

        passage.Initialize(space, otherSpace, direction);
        passage = Instantiate(passagePrefab);
        passage.Initialize(otherSpace, space, direction.Opposite());
    }
コード例 #29
0
ファイル: BoardSpace.cs プロジェクト: rcornwal/DotsGame
 public AdjacentSpaces(BoardSpace _left, BoardSpace _right,
                       BoardSpace _top, BoardSpace _bottom)
 {
     Left   = _left;
     Right  = _right;
     Top    = _top;
     Bottom = _bottom;
 }
コード例 #30
0
    //MakeMove for ai calculation in negamax
    public void MakeMove(int[,] gameBoard, BoardSpace space, int player)
    {
        //Debug.Log("MakeMove space x, y: " + space.x + ", " + space.y + "\n");

        //Debug.Log("gameBoard length: " + gameBoard.GetLength(0));

        gameBoard[space.x, space.y] = player;
    }
コード例 #31
0
 public void BoardSpaceSelected(BoardSpace board)
 {
     if (!isMoving)
     {
         Cat.moveToBoard = board;
         canSelectMove   = false;
     }
 }
コード例 #32
0
 /// <summary>
 /// Sets the spaceState for the passed in BoardSpace to reflect whether the space is open, blocked or contested.
 /// Returns the passed in BoardSpace if it is a valid move location for the activePiece. Returns null otherwise.
 /// </summary>
 /// <returns></returns>
 public BoardSpace checkSpace(BoardSpace spaceToCheck)
 {
     ChessPiece activePiece = GameManager.currentInstance.activePiece;
     TeamColor PieceColor = activePiece.PieceColor;
     if ((activePiece != null) && (spaceToCheck != null))  //ensure there is and activePiece and a valid spaceToCheck
     {
         if (spaceToCheck.OccupyingPiece != null)    //is the space occupied
         {
             //Debug.Log(spaceToCheck.OccupyingPiece);
             //Debug.Log(spaceToCheck.OccupyingPiece.PieceColor == PieceColor);
             if (spaceToCheck.OccupyingPiece.PieceColor == PieceColor) //is the OccupyingPiece the same color as the activePiece
             {
                 spaceToCheck.spaceState = SpaceState.Blocked;   //space is blocked
                 //Debug.Log(spaceToCheck.spaceState);
                 return null;                                    //can't move here; return null
             }
             else                                                       //is the OccupyingPiece a different color than the activePiece
             {
                 if (spaceToCheck.OccupyingPiece.GetType() == typeof(King))  //piece an enemy king?
                 {
                     spaceToCheck.spaceState = SpaceState.Blocked;       //space is blocked
                     return null;                                      //can't move here; return null
                 }
                 else
                 {
                     spaceToCheck.spaceState = SpaceState.Contested;   //space is contested
                     return spaceToCheck;                              //can capture here; return the space
                 }
             }
         }
         else
         {
             spaceToCheck.spaceState = SpaceState.Open;
             return spaceToCheck;
         }
     }
     else
     {
         return null;
     }
 }
コード例 #33
0
ファイル: GameBoard.cs プロジェクト: immeraufdemhund/StoneAge
 public Card GetCardFromSpace(BoardSpace cardSlot)
 {
     Card card;
     switch (cardSlot)
     {
         case BoardSpace.CivilizationCardSlot1:
             card = CardSlot1;
             break;
         case BoardSpace.CivilizationCardSlot2:
             card = CardSlot2;
             break;
         case BoardSpace.CivilizationCardSlot3:
             card = CardSlot3;
             break;
         case BoardSpace.CivilizationCardSlot4:
             card = CardSlot4;
             break;
         default:
             throw new InvalidSpaceForCardsException(cardSlot);
     }
     return card;
 }
コード例 #34
0
ファイル: BestMoveResult.cs プロジェクト: aldenquimby/cs4701
 public BestMoveResult(int score, BoardSpace bestMove)
 {
     Move = bestMove;
     Score = score;
 }
コード例 #35
0
ファイル: GameTest.cs プロジェクト: immeraufdemhund/StoneAge
        public void Using_civilization_card_slots_allows_for_payment_of_cards(BoardSpace cardSlot)
        {
            SetupUltimate2PlayerGame();
            game.PlacePeople(player1, 1, cardSlot);
            game.PlacePeople(player2, 10, BoardSpace.HuntingGrounds);
            game.PlacePeople(player1, 9, BoardSpace.HuntingGrounds);

            var result = game.UseActionOfPeople(player1, cardSlot);

            Assert.IsTrue(result.Successful);

            int cost = (int)cardSlot - (int)BoardSpace.CivilizationCardSlot1 + 1;
            var payResult = game.PayForCard(player1, new Dictionary<Resource, int> { {Resource.Wood, cost}});
            Assert.IsTrue(payResult.Successful);
        }
コード例 #36
0
ファイル: BestMoveResult.cs プロジェクト: aldenquimby/cs4701
 public BestMoveResultWithStats(int score, BoardSpace bestMove)
 {
     Move = bestMove;
     Score = score;
     NodesGeneratedByDepth = new Dictionary<int, int>();
 }
コード例 #37
0
 public InvalidSpaceForCardsException(BoardSpace space)
     : base(string.Format("Cannot find card for a non card slot space {0}.", space))
 {
 }
コード例 #38
0
        private void Init2DBoard()
        {
            this.TurnPicture.Image = global::doubleStuffed.Properties.Resources.black_turn;
            for (int row = 0; row < 8; row++)
            {
                for (int column = 0; column < 8; column++)
                {
                    buttonArray[row, column] = new BoardSpace(column, row);
                    buttonArray[row, column].Size = new Size(58, 58);
                    buttonArray[row, column].Location = new Point(84 + column * 62, 55 + row * 62);
                    this.Controls.Add(buttonArray[row, column]);
                    buttonArray[row, column].Click += BoardSpaceClicker;
                    this.gamePanel.Controls.Add(buttonArray[row, column]);

                    buttonArray[row, column].BringToFront();
                    buttonArray[row, column].FlatAppearance.BorderSize = 0;
                    buttonArray[row, column].FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                    buttonArray[row, column].BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                    int state = tempObj.GameBoard.Spaces[row, column];
                    switch (state)
                    {
                        case 0:
                            buttonArray[row, column].BackgroundImage = null;
                            break;
                        case 1:
                            buttonArray[row, column].BackgroundImage = global::doubleStuffed.Properties.Resources.white_token;
                            break;
                        case 2:
                            buttonArray[row, column].BackgroundImage = global::doubleStuffed.Properties.Resources.black_token;
                            break;
                        case 3:
                            buttonArray[row, column].BackgroundImage = Properties.Resources.game_board_bg_cropped;
                            break;
                    }
                }
            }
        }
コード例 #39
0
 public int[] getIndex(BoardSpace space)
 {
     return new int[]
     {
         (int) Enum.Parse (typeof(Column), space.spaceColumn.ToString ()),
         (int) (int.Parse (space.spaceRow.ToString ()) - 1)
     };
 }
コード例 #40
0
    ///// <summary>
    ///// Returns true if the adjacent space in the specified direction of the current space for the specified team color.
    ///// </summary>
    ///// <param name="currentSpace"></param>
    ///// <param name="direction"></param>
    ///// <param name="PieceColor"></param>
    ///// <returns></returns>
    //public bool isSpaceAvailable(BoardSpace spaceToCheck, TeamColor pieceColor)
    //{
    //    int[] indexArray = getIndex(spaceToCheck);
    //    if (spaceToCheck.OccupyingPiece != null)
    //    {
    //        if (spaceToCheck.OccupyingPiece.PieceColor == pieceColor)
    //        {
    //            spaceToCheck.spaceState = SpaceState.Blocked;
    //            return false;
    //        }
    //        else
    //        {
    //            spaceToCheck.spaceState = SpaceState.Contested;
    //            return true;
    //        }
    //    }
    //    else
    //    {
    //        spaceToCheck.spaceState = SpaceState.Open;
    //    }
    //    return true;
    //}
    /// <summary>
    /// Returns the space directly next to currentSpace in the specified direction. Retunrns null if the space does not exist.
    /// If validate is true, the function will return the board space only if the space is a valid move for currentSpace's occupying piece and will return null otherwise.
    /// </summary>
    /// <param name="currentSpace"></param>
    /// <param name="direction"></param>
    /// <param name="pieceColor"></param>
    /// <param name="Validate"></param>
    /// <returns></returns>
    public BoardSpace getAdjacentSpace(BoardSpace currentSpace, SpaceDirection direction, TeamColor pieceColor, bool Validate)
    {
        if (currentSpace != null)
        {
            int[] indexArray = getIndex(currentSpace);
            ChessPiece activePiece = GameManager.currentInstance.activePiece;

            //Determine newSpaceRow and newSpaceColumn by checking arguments
            switch (direction)
            {
                case (SpaceDirection.FrontLeft):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    break;

                case (SpaceDirection.Front):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[1] -= 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[1] += 1; //Row
                    }
                    break;

                case (SpaceDirection.FrontRight):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    break;

                case (SpaceDirection.Left):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] += 1; //Column
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] -= 1; //Column
                    }
                    break;

                case (SpaceDirection.Right):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] -= 1; //Column
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] += 1; //Column
                    }
                    break;

                case (SpaceDirection.BackLeft):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    break;

                case (SpaceDirection.Back):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[1] += 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[1] -= 1; //Row
                    }
                    break;

                case (SpaceDirection.BackRight):
                    if (pieceColor == TeamColor.Black)
                    {
                        indexArray[0] -= 1; //Column
                        indexArray[1] += 1; //Row
                    }
                    else if (pieceColor == TeamColor.White)
                    {
                        indexArray[0] += 1; //Column
                        indexArray[1] -= 1; //Row
                    }
                    break;

                default:
                    break;
            }
            if ((indexArray[0] < 0) || (indexArray[1] < 0) || (indexArray[0] > 7) || (indexArray[1] > 7)) //space is outside of the board
            {
                return null;
            }
            BoardSpace newSpace = spaces[indexArray[0], indexArray[1]];
            if (Validate)
            {
                    return checkSpace(newSpace);

            }
            return newSpace;

        }
        return null;
    }
コード例 #41
0
 /// <summary>
 /// Moves the GameManager's activePiece to the destination BoardSpace.
 /// </summary>
 /// <param name="destination"></param>
 public void MovePiece(BoardSpace destination)
 {
     MovePiece(activePiece, destination);
 }
コード例 #42
0
    /// <summary>
    /// Returns all knights checking the space (relative to the teamColor); null if there are none
    /// </summary>
    /// <param name="space"></param>
    /// <param name="teamColor"></param>
    /// <returns></returns>
    private Knight[] checkedByKnights(BoardSpace space, TeamColor teamColor)
    {
        List<Knight> checkingKnights = new List<Knight>();
        BoardSpace tempSpace, sideSpace;
        //CHECK FRONT LEFT / FRONT RIGHT
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, SpaceDirection.Front, teamColor, false);
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Front, teamColor, false);
        sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Left, teamColor, false);
        if ((sideSpace != null) && (sideSpace.OccupyingPiece != null))
        {
            if ((sideSpace.OccupyingPiece.PieceColor != teamColor) && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight) sideSpace.OccupyingPiece);
            }
            sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Right, teamColor, false);
            if ((sideSpace != null) && (sideSpace.OccupyingPiece != null) && (sideSpace.OccupyingPiece.PieceColor != teamColor)
                && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight)sideSpace.OccupyingPiece);
            }
        }

        //CHECK LEFT FRONT / LEFT BACK
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, SpaceDirection.Left, teamColor, false);
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Left, teamColor, false);
        sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Front, teamColor, false);
        if ((sideSpace != null) && (sideSpace.OccupyingPiece != null))
        {
            if ((sideSpace.OccupyingPiece.PieceColor != teamColor) && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight)sideSpace.OccupyingPiece);
            }
            sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Back, teamColor, false);
            if ((sideSpace != null) && (sideSpace.OccupyingPiece != null) && (sideSpace.OccupyingPiece.PieceColor != teamColor)
                && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight)sideSpace.OccupyingPiece);
            }
        }

        //CHECK RIGHT FRONT / RIGHT BACK
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, SpaceDirection.Right, teamColor, false);
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Right, teamColor, false);
        sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Front, teamColor, false);
        if ((sideSpace != null) && (sideSpace.OccupyingPiece != null))
        {
            if ((sideSpace.OccupyingPiece.PieceColor != teamColor) && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight)sideSpace.OccupyingPiece);
            }
            sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Back, teamColor, false);
            if ((sideSpace != null) && (sideSpace.OccupyingPiece != null) && (sideSpace.OccupyingPiece.PieceColor != teamColor)
                && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight)sideSpace.OccupyingPiece);
            }
        }

        //CHECK BACK LEFT / BACK RIGHT
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, SpaceDirection.Back, teamColor, false);
        tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Back, teamColor, false);
        sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Left, teamColor, false);
        if ((sideSpace != null) && (sideSpace.OccupyingPiece != null))
        {
            if ((sideSpace.OccupyingPiece.PieceColor != teamColor) && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight)sideSpace.OccupyingPiece);
            }
            sideSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, SpaceDirection.Right, teamColor, false);
            if ((sideSpace != null) && (sideSpace.OccupyingPiece != null) && (sideSpace.OccupyingPiece.PieceColor != teamColor)
                && (sideSpace.OccupyingPiece.GetType() == typeof(Knight)))
            {
                //Debug.Log("Space Checked by Knight");
                checkingKnights.Add((Knight)sideSpace.OccupyingPiece);
            }
        }
        if (checkingKnights != null)
        {
            return checkingKnights.ToArray();
        }
        return null;
    }
コード例 #43
0
ファイル: GameTest.cs プロジェクト: immeraufdemhund/StoneAge
        public void Can_place_7_people_in_locations(BoardSpace space)
        {
            SetupUltimate2PlayerGame();

            var result = game.PlacePeople(player1, 7, space);

            Assert.IsTrue(result.Successful);
        }
コード例 #44
0
 private void HideSpaces(BoardSpace[] spacesToHide)
 {
     foreach (BoardSpace space in spacesToHide)
     {
         if (space != null)
         {
             Renderer meshRenderer = space.GetComponent<Renderer>();
             Collider spaceCollider = space.GetComponent<Collider>();
             meshRenderer.enabled = false;
             spaceCollider.enabled = false;
         }
     }
 }
コード例 #45
0
 private void DisplaySpaces(BoardSpace[] spacesToDisplay)
 {
     foreach (BoardSpace space in spacesToDisplay)
     {
         if (space != null)
         {
             Renderer meshRenderer = space.GetComponent<Renderer>();
             Collider spaceCollider = space.GetComponent<Collider>();
             switch (space.spaceState){
                 case SpaceState.Contested:
                     meshRenderer.material = materialLibrary.materialSpaceContested;
                     break;
                 case SpaceState.Open:
                     meshRenderer.material = materialLibrary.materialSpaceOpen;
                     break;
                 case SpaceState.Blocked:
                     meshRenderer.material = materialLibrary.materialSpaceOpen;
                     break;
                 default:
                     meshRenderer.material = materialLibrary.materialSpaceOpen;
                     break;
             }
             meshRenderer.enabled = true;
             spaceCollider.enabled = true;
         }
     }
 }
コード例 #46
0
 /// <summary>
 /// Checks whether or not a Castle Move occured and moves the appropriate Rook if so.
 /// </summary>
 /// <param name="king"></param>
 /// <param name="destination"></param>
 private void castleMove(ChessPiece king, BoardSpace destination)
 {
     ChessPiece rook;
     BoardSpace rookSpace;
     Debug.Log("Running castleMove()");
     switch (king.PieceColor)
     {
         case (TeamColor.Black):
             if (destination.name == "C8")
             {
                 rook = GameObject.Find("A8").GetComponent<BoardSpace>().OccupyingPiece;
                 rookSpace = GameObject.Find("D8").GetComponent<BoardSpace>();
                 MovePiece(rook, rookSpace);
                 turnTeamColor = king.PieceColor;
             }
             else if (destination.name == "G8")
             {
                 rook = GameObject.Find("H8").GetComponent<BoardSpace>().OccupyingPiece;
                 rookSpace = GameObject.Find("F8").GetComponent<BoardSpace>();
                 MovePiece(rook, rookSpace);
                 turnTeamColor = king.PieceColor;
             }
             break;
         case (TeamColor.White):
             if (destination.name == "C1")
             {
                 rook = GameObject.Find("A1").GetComponent<BoardSpace>().OccupyingPiece;
                 rookSpace = GameObject.Find("D1").GetComponent<BoardSpace>();
                 MovePiece(rook, rookSpace);
                 turnTeamColor = king.PieceColor;
             }
             else if (destination.name == "G1")
             {
                 rook = GameObject.Find("H1").GetComponent<BoardSpace>().OccupyingPiece;
                 rookSpace = GameObject.Find("F1").GetComponent<BoardSpace>();
                 MovePiece(rook, rookSpace);
                 turnTeamColor = king.PieceColor;
             }
             break;
     }
 }
コード例 #47
0
 /// <summary>
 /// Moves a passed in ChessPiece to the destination BoardSpace
 /// </summary>
 /// <param name="pieceToMove"></param>
 /// <param name="destination"></param>
 public void MovePiece(ChessPiece piece, BoardSpace destination)
 {
     if ((piece.GetType() == typeof(King)) && ((piece as King).CanCastle)) {
         castleMove(piece, destination);
     }
     piece.transform.position = new Vector3(destination.transform.position.x,piece.transform.position.y, destination.transform.position.z);
     piece.currentSpace.OccupyingPiece = null;   //clear old space's OccupyingPiece
     piece.currentSpace = destination;
     destination.OccupyingPiece = piece;
     piece.bHasMoved = true;
     ChangeTurn();
 }
コード例 #48
0
    /// <summary>
    /// Takes a space and direction and returns the nearest checking piece from the specified direction (returns null if there is no checking piece.)
    /// </summary>
    /// <param name="space"></param>
    /// <param name="direction"></param>
    private ChessPiece checkedFromDirection(BoardSpace space, SpaceDirection direction, TeamColor teamColor)
    {
        BoardSpace tempSpace;
        if ((direction == SpaceDirection.Front) || (direction == SpaceDirection.Back) || (direction == SpaceDirection.Left) || (direction == SpaceDirection.Right))
        {
            tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false);
            while ((tempSpace != null) && ((tempSpace.OccupyingPiece == null) || ((tempSpace.OccupyingPiece.PieceColor == teamColor) && (tempSpace.OccupyingPiece.GetType() == typeof(King)))))
            {
                tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, direction, teamColor, false); //search for piece on forward column
            }

            if (tempSpace != null)  //piece found; not the end of Board
            {
                if ((tempSpace.OccupyingPiece != null) && (tempSpace.OccupyingPiece.PieceColor != teamColor))  //piece is an enemy piece
                {
                    switch ((tempSpace.OccupyingPiece.GetType().ToString()))  //is the piece one that can capture along the column?
                    {
                        case ("Rook"):
                            return tempSpace.OccupyingPiece;
                        case ("Queen"):
                            return tempSpace.OccupyingPiece;
                        case ("King"):
                            if (tempSpace == GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false))
                            {
                                return tempSpace.OccupyingPiece;
                            }
                            break;
                        default:
                            Debug.Log("Returning null...");
                            return null;
                    }
                }
            }
        }
        else if ((direction == SpaceDirection.FrontLeft) || (direction == SpaceDirection.FrontRight) || (direction == SpaceDirection.BackLeft) || (direction == SpaceDirection.BackRight))
        {
            tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false);
            while ((tempSpace != null) &&(tempSpace.OccupyingPiece == null))
            {
                tempSpace = GameManager.currentInstance.Board.getAdjacentSpace(tempSpace, direction, teamColor, false); //search for piece on forward column
            }
            if (tempSpace != null)  //piece found; not the end of Board
            {
                if ((tempSpace.OccupyingPiece != null) && (tempSpace.OccupyingPiece.PieceColor != teamColor))  //piece is an enemy piece
                {

                    switch ((tempSpace.OccupyingPiece.GetType().ToString()))  //is the piece one that can capture along the diagonal?
                    {
                        case ("Bishop"):
                            return tempSpace.OccupyingPiece;
                        case ("Queen"):
                            return tempSpace.OccupyingPiece;
                        case ("King"):
                            if (tempSpace == GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false))
                            {
                                return tempSpace.OccupyingPiece;
                            }
                            break;
                        case ("Pawn"):
                            if (tempSpace == GameManager.currentInstance.Board.getAdjacentSpace(space, direction, teamColor, false))
                            {
                                return tempSpace.OccupyingPiece;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        return null;
    }
コード例 #49
0
ファイル: GameTest.cs プロジェクト: immeraufdemhund/StoneAge
        public void Can_only_place_1_person_in_locations(BoardSpace space)
        {
            SetUpStandard2PlayerGame();

            var result = game.PlacePeople(player1, 1, space);

            Assert.IsTrue(result.Successful);
        }
コード例 #50
0
    //if (activePiece.GetType() == typeof (Knight)){
    //    if ((activePiece as Knight).IsLastSpace)
    //    {
    //    }
    //}
    /// <summary>
    /// Returns true if the passed in space is checked by a piece with a color other than the one passed in.
    /// </summary>
    /// <param name="space"></param>
    /// <returns></returns>
    public bool isSpaceChecked(BoardSpace space, TeamColor teamColor)
    {
        // Logical OR of possible checked conditions
        bool Checked = ((checkedFromDirection(space, SpaceDirection.FrontLeft, teamColor) != null) || (checkedFromDirection(space, SpaceDirection.Front, teamColor) != null) || (checkedFromDirection(space, SpaceDirection.FrontRight, teamColor) != null)
            || (checkedFromDirection(space, SpaceDirection.Left, teamColor) != null) || (checkedFromDirection(space, SpaceDirection.Right, teamColor) != null) || (checkedFromDirection(space, SpaceDirection.BackLeft, teamColor) != null)
            || (checkedFromDirection(space, SpaceDirection.Back, teamColor) != null) || (checkedFromDirection(space, SpaceDirection.BackRight, teamColor) != null) || checkedByKnights(space, teamColor) != null);
        Debug.Log(space);
        Debug.Log(checkedFromDirection(space, SpaceDirection.FrontLeft, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.Front, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.FrontRight, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.Left, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.Right, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.BackLeft, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.Back, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.BackRight, teamColor));
        Debug.Log(checkedFromDirection(space, SpaceDirection.Front, teamColor));
        Debug.Log(checkedByKnights(space, teamColor) != null);

        return Checked;
    }
コード例 #51
0
ファイル: GameTest.cs プロジェクト: immeraufdemhund/StoneAge
        public void Cannot_place_8_people_in_locations(BoardSpace space)
        {
            SetUpStandard2PlayerGame();

            var result = game.PlacePeople(player1, 8, space);

            Assert.IsFalse(result.Successful);
        }
コード例 #52
0
 /// <summary>
 /// Function that returns all pieces currently checking the potential space of a king of the specified teamColor. (Returns null if there are none.)  
 /// </summary>
 /// <param name="space"></param>
 /// <param name="teamColor"></param>
 /// <returns></returns>
 public ChessPiece[] getCheckingPieces(BoardSpace space, TeamColor teamColor)
 {
     List<ChessPiece> checkingPieces = new List<ChessPiece>();
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.FrontLeft, teamColor));
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.Front, teamColor));
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.FrontRight, teamColor));
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.Left, teamColor));
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.Right, teamColor));
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.BackLeft, teamColor));
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.Back, teamColor));
     checkingPieces.Add(checkedFromDirection(space, SpaceDirection.BackRight, teamColor));
     foreach (Knight checkingKnight in checkedByKnights(space, teamColor))
     {
         checkingPieces.Add(checkingKnight);
     }
     return checkingPieces.ToArray();
 }
コード例 #53
0
ファイル: Heuristics.cs プロジェクト: aldenquimby/cs4701
        private static IEnumerable<BoardSpace> GetSurroundingSpaces(BoardSpace space)
        {
            var higherRow = (byte)(space.Row + 1);
            var lowerRow = (byte)(space.Row - 1);
            var higherCol = (byte)(space.Col + 1);
            var lowerCol = (byte)(space.Col - 1);

            if (space.Row > 0)
            {
                yield return new BoardSpace(lowerRow, space.Col);

                if (space.Col > 0)
                {
                    yield return new BoardSpace(lowerRow, lowerCol);
                    yield return new BoardSpace(space.Row, lowerCol);
                }
                if (space.Col < 7)
                {
                    yield return new BoardSpace(lowerRow, higherCol);
                    yield return new BoardSpace(space.Row, higherCol);
                }
            }
            if (space.Row < 7)
            {
                yield return new BoardSpace(higherRow, space.Col);

                if (space.Col > 0)
                {
                    yield return new BoardSpace(higherRow, lowerCol);
                }
                if (space.Col < 7)
                {
                    yield return new BoardSpace(higherRow, higherCol);
                }
            }
        }
コード例 #54
0
 /// <summary>
 /// Checks if there is a Pawn in position for En Passant; updates the private bool enPassantThreatened.
 /// </summary>
 /// <param name="firstSpace"></param>
 /// <returns></returns>
 void EnPassantCheck(BoardSpace firstSpace)
 {
     //Debug.Log("EnPassantCheck() ran");
     //Check for an enPassant Pawn
     BoardSpace frontLeftSpace = GameManager.currentInstance.Board.getAdjacentSpace(firstSpace, SpaceDirection.FrontLeft, PieceColor, false);
     BoardSpace frontRightSpace = GameManager.currentInstance.Board.getAdjacentSpace(firstSpace, SpaceDirection.FrontRight, PieceColor, false);
     GameManager.currentInstance.Board.checkSpace(frontLeftSpace);
     GameManager.currentInstance.Board.checkSpace(frontRightSpace);
     if ((frontLeftSpace != null) && (frontLeftSpace.spaceState == SpaceState.Contested))
     {
         if ((frontLeftSpace.OccupyingPiece.GetType() == typeof(Pawn)))
         {
             //Debug.Log("In Here(L)");
             EnPassantThreatened = true;
             Pawn.EnPassantPossible = true;
         }
     }
     if ((frontRightSpace != null) && (frontRightSpace.spaceState == SpaceState.Contested))
     {
         if ((frontRightSpace.OccupyingPiece.GetType() == typeof(Pawn)))
         {
             //Debug.Log("In Here(R)");
             EnPassantThreatened = true;
             Pawn.EnPassantPossible = true;
         }
     }
 }
コード例 #55
0
ファイル: Game.cs プロジェクト: immeraufdemhund/StoneAge
        public GameResponse PlacePeople(Guid playerId, int quantity, BoardSpace boardSpace)
        {
            if (Phase != GamePhase.PlayersPlacePeople)
                return GameResponse.Fail();

            var player = _players.SingleOrDefault(p => p.Id == playerId);
            if (player == null)
                return GameResponse.Fail();

            if (TurnOrder.Current != player)
                return GameResponse.Fail();

            var space = Board.Spaces.SingleOrDefault(s => s.BoardSpace == boardSpace);
            if (space.QuantityIsInvalidForSpace(quantity))
                return GameResponse.Fail();

            if(space.PlayerPreviouslyPlaced(player) && !space.AllowsPartialPlacement)
                return GameResponse.Fail();

            if(space.NotAvailable(quantity))
                return GameResponse.Fail();

            if(space.HasTooManyUniquePlayers())
                return GameResponse.Fail();

            if(!player.PlayerBoard.HasAvailablePeopleToPlace(quantity))
                return GameResponse.Fail();

            player.PlayerBoard.SetPeopleAsPlaced(quantity);
            space.Place(player, quantity);

            if (_players.Sum(p => p.PlayerBoard.PeopleToPlace) == 0)
            {
                Phase = GamePhase.UsePeopleActions;
                TurnOrder.SetCheiftanToCurrent();
            }
            else
            {
                TurnOrder.NextPlayerToPlace();
            }

            return GameResponse.Pass();
        }
コード例 #56
0
ファイル: Game.cs プロジェクト: immeraufdemhund/StoneAge
        public GameResponse<DiceResult> UseActionOfPeople(Guid playerId, BoardSpace boardSpace)
        {
            if (Phase != GamePhase.UsePeopleActions)
                return GameResponse<DiceResult>.Fail();

            var player = _players.SingleOrDefault(p => p.Id == playerId);
            if (player == null)
                return GameResponse<DiceResult>.Fail();

            if(player != TurnOrder.Current)
                return GameResponse<DiceResult>.Fail();

            var space = Board.Spaces.SingleOrDefault(s => s.BoardSpace == boardSpace);
            if(!space.PlayerPreviouslyPlaced(player))
                return GameResponse<DiceResult>.Fail();

            var diceResult = UseAction(player, space);

            if (player.PlayerBoard.PeopleToPlace == player.PlayerBoard.TotalPeople)
                TurnOrder.Next();

            if (_players.Sum(p => p.PlayerBoard.PeopleToPlace) == _players.Sum(p => p.PlayerBoard.TotalPeople))
            {
                foreach (var playerToChange in _players)
                    playerToChange.NeedsToFeed = true;
                Phase = GamePhase.FeedPeople;
            }

            return GameResponse<DiceResult>.Pass(diceResult);
        }
コード例 #57
0
ファイル: GameRunner.cs プロジェクト: aldenquimby/cs4701
        // ask user for next opponent move
        private static BoardSpace GetOpponentMove()
        {
            Console.WriteLine("Enter opponent move (row col):");

            BoardSpace move = null;

            while (move == null)
            {
                try
                {
                    move = new BoardSpace(Console.ReadLine());
                }
                catch
                {
                    Console.WriteLine("Error reading move, use the format (row col):");
                }
            }

            return move;
        }