Пример #1
0
 private void changeTurn()
 {
     if (player_turn == PieceConfig.Color.blue)
     {
         red_text.SetActive(true);
         blue_text.SetActive(false);
         player_turn = PieceConfig.Color.red;
     }
     else
     {
         red_text.SetActive(false);
         blue_text.SetActive(true);
         player_turn = PieceConfig.Color.blue;
     }
 }
Пример #2
0
 private bool OpposingTeam(GameObject piece, PieceConfig.Color color)
 {
     if (piece == null)
     {
         return(true);
     }
     PieceConfig.Color piece_color = piece.GetComponent <PieceConfig>().piece_color;
     if (piece_color != color)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
    public override LinkedList <Vector3Int> GetMovePositions(Vector3Int pos, GameObject[,] board_state)
    {
        LinkedList <Vector3Int> pos_list = new LinkedList <Vector3Int>();

        PieceConfig.Color color = this.GetComponent <PieceConfig>().piece_color;

        if (color == PieceConfig.Color.blue)
        {
            pos_list.AddLast(new Vector3Int(pos.x, pos.y + 1, 1));
            try
            {
                if (first_move && board_state[pos.x, pos.y + 1] == null)
                {
                    pos_list.AddLast(new Vector3Int(pos.x, pos.y + 2, 1));
                }
            }
            catch (System.Exception) { }
            pos_list.AddLast(new Vector3Int(pos.x + 1, pos.y + 1, 2));
            pos_list.AddLast(new Vector3Int(pos.x - 1, pos.y + 1, 2));
        }
        else
        {
            pos_list.AddLast(new Vector3Int(pos.x, pos.y - 1, 1));
            try
            {
                if (first_move && board_state[pos.x, pos.y - 1] == null)
                {
                    pos_list.AddLast(new Vector3Int(pos.x, pos.y - 2, 1));
                }
            }
            catch (System.Exception) { }
            pos_list.AddLast(new Vector3Int(pos.x + 1, pos.y - 1, 2));
            pos_list.AddLast(new Vector3Int(pos.x - 1, pos.y - 1, 2));
        }

        return(EliminateWrongPos(pos_list, color, board_state));
    }
Пример #4
0
    public LinkedList <Vector3Int> EliminateWrongPos(LinkedList <Vector3Int> pos_list, PieceConfig.Color color, GameObject[,] board)
    {
        List <Vector3Int> aux_list = new List <Vector3Int>(pos_list);

        foreach (Vector3Int pos in aux_list)
        {
            if (pos.x >= 8 || pos.x < 0 || pos.y >= 8 || pos.y < 0)
            {
                pos_list.Remove(pos);
            }
        }

        aux_list = new List <Vector3Int>(pos_list);

        foreach (Vector3Int pos in aux_list)
        {
            switch (pos.z)
            {
            case 0:
                if (!OpposingTeam(board[pos.x, pos.y], color))
                {
                    pos_list.Remove(pos);
                }
                else
                {
                    if (board[pos.x, pos.y] == null)
                    {
                        pos_list.Find(pos).Value = new Vector3Int(pos.x, pos.y, 0);
                    }
                    else
                    {
                        pos_list.Find(pos).Value = new Vector3Int(pos.x, pos.y, 1);
                    }
                }
                continue;

            case 1:
                if (board[pos.x, pos.y] != null)
                {
                    pos_list.Remove(pos);
                }
                else
                {
                    pos_list.Find(pos).Value = new Vector3Int(pos.x, pos.y, 0);
                }
                continue;

            case 2:
                if (board[pos.x, pos.y] == null || !OpposingTeam(board[pos.x, pos.y], color))
                {
                    pos_list.Remove(pos);
                }
                else
                {
                    pos_list.Find(pos).Value = new Vector3Int(pos.x, pos.y, 1);
                }
                continue;
            }
        }

        return(pos_list);
    }