예제 #1
0
    // @return  True if the specified color can play in the given Point
    public bool IsValidPlay(Vector2 point, GoColor colorStone)
    {
        int x = (int)point.x;
        int y = (int)point.y;

        // Check: If Point is empty. If not, we cannot play there
        if (!IsPointEmpty(point))
        {
            Debug.Log("[GB] Could not create @ ( " + x + ", " + y + "); already occupied");
            return(false);
        }

        // Check: If new Stone would be immediately be captured
        if (IsGroupCaptured(point, colorStone))
        {
            // If a Stone would immediately be captured, we can play it
            // IFF that move would capture enemy Stone(s)
            // AND we aren't violating the rule of Ko
            List <Vector2> list_blocked = new List <Vector2>();
            list_blocked.Add(point);

            // Check adjacent spots to see if we can capture enemy Stone(s)
            List <Vector2> list_adjacent      = GetAdjacentPoints(point);
            bool           b_capture_detected = false;
            foreach (Vector2 point_adj in list_adjacent)
            {
                GoPoint gp_adj = gridPoints[(int)point_adj.x, (int)point_adj.y];
                // We only care about checking against enemy stones

                GoStone stone_adj = gp_adj.GetStone();
                if (stone_adj.Color != colorStone)
                {
                    b_capture_detected |= IsGroupCaptured(point_adj, stone_adj.Color, list_blocked);
                }
            }

            // If no captured were found, play is illegal
            if (!b_capture_detected)
            {
                Debug.Log("[GB] Could not create @ ( " + x + ", " + y + "); illegal move (surrounded)");
                return(false);
            }
            // Check for Ko
            else
            {
                GoTurn turn_prev = gameStateManager.GetTurnPrev();
                if (turn_prev.piecesCaptured == 1 && IsGroupCaptured(turn_prev.pointPlay, turn_prev.turnColor, list_blocked))
                {
                    Debug.Log("[GB] Could not create @ ( " + x + ", " + y + "); illegal move (Ko)");
                    return(false);
                }
            }
        }

        return(true);
    }
예제 #2
0
    // @return true if space was previously empty; false otherwise (should always be true in normal circumstances)
    public bool SetPiece(GoStone piece)
    {
        GoStone piece_prev = GoPiece;

        GoPiece = piece;

        // :TODO: Delete piece_prev?

        return(piece_prev == null);
    }
예제 #3
0
    // Place piece on the board and handle board state management
    private void PlacePiece(GoStone piece, Vector2 pointGrid)
    {
        int     point_x        = (int)pointGrid.x;
        int     point_y        = (int)pointGrid.y;
        GoPoint point_center   = gridPoints[point_x, point_y];
        GoColor color_attacker = piece.Color;
        GoColor color_enemy    = (color_attacker == GoColor.GC_Black ? GoColor.GC_White : GoColor.GC_Black);

        // Place GoPiece GameObject in the GoPoint
        point_center.SetPiece(piece);

        //// Decrement neighboring point's empty count
        //UpdateAdjacentEmptySpaces(pointGrid, (color_attacker == GoColor.GC_Black));

        // Check if we have captured any enemy pieces (Up/Down/Left/Right
        Queue <Vector2> queue_adjacents = new Queue <Vector2>();
        List <Vector2>  list_adj        = GetAdjacentPoints(pointGrid);

        foreach (Vector2 point_adj in list_adj)
        {
            queue_adjacents.Enqueue(point_adj);
        }

        int count_captured = 0;

        while (queue_adjacents.Count > 0)
        {
            // Retrieve Vector2
            Vector2 vec_curr = queue_adjacents.Dequeue();

            // Check if valid
            if (IsValidPoint(vec_curr))
            {
                // Retrieve GoPoint
                GoPoint point_curr = gridPoints[(int)vec_curr.x, (int)vec_curr.y];
                // Check if valid, if enemy color
                if (!point_curr.IsEmpty() && point_curr.GetStone().Color == color_enemy)
                {
                    // If so, check if surrounded.
                    if (IsGroupCaptured(vec_curr, color_enemy))
                    {
                        // If so, remove group and report score to GoStateManager
                        count_captured += TryCaptureGroup(vec_curr, color_enemy);
                    }
                }
            }
        }

        // Report captured stones
        if (count_captured > 0)
        {
            gameStateManager.OnStonesCaptured(color_attacker, count_captured);
        }
    }
예제 #4
0
    public bool RemovePiece()
    {
        bool b_removed = false;

        if (!IsEmpty())
        {
            Object.Destroy(GoPiece.gameObject);
            b_removed = true;
        }
        GoPiece = null;

        return(b_removed);
    }
예제 #5
0
파일: GoGame.cs 프로젝트: dimetcm/RLBoard
    public void OnClicked(GoBoardIntersection intersection)
    {
        GoStone stone = new GoStone(intersection.X, intersection.Y);

        if (!m_whiteStones.Contains(stone) && !m_blackStones.Contains(stone))
        {
            if (m_currentPlayerColor == StoneColor.White)
            {
                m_whiteStones.Add(stone);
            }
            else
            {
                m_blackStones.Add(stone);
            }
            m_boardVisual.PlaceStone(intersection, m_currentPlayerColor);
            m_currentPlayerColor = m_currentPlayerColor == StoneColor.White ? StoneColor.Black : StoneColor.White;
        }
    }
예제 #6
0
    // Creates GameObject  in the 3D world
    private GoStone CreatePiece(Vector3 posSpawn, bool bIsBlack)
    {
        GoStone piece_new = Instantiate((bIsBlack ? prefabPieceBlack : prefabPieceWhite), posSpawn /*new Vector3(-0.5f, 0.0f, -1.0f)*/, Quaternion.identity, transform);

        return(piece_new);
    }