Esempio n. 1
0
    public List <Index> GetPossibleLocation(GridBox.Status color)
    {
        var list = new List <Index>();

        for (var i = 0; i < 8; i++)
        {
            for (var j = 0; j < 8; j++)
            {
                List <GridBox> dummy;
                if (CheckPieceValid(color, new Index(i, j), out dummy))
                {
                    list.Add(new Index(i, j));
                }
            }
        }

        if (list.Count != 0)
        {
            return(list);
        }
        else
        {
            if (blackPieces.Count + whitePieces.Count == 8 * 8)
            {
                if (blackPieces.Count < whitePieces.Count)
                {
                    indicatorText.text = "White Win";
                }
                else if (blackPieces.Count > whitePieces.Count)
                {
                    indicatorText.text = "Black Win";
                }
                else
                {
                    indicatorText.text = "Drew";
                }

                isGameEnd = true;

                return(null);
            }

            indicatorText.text  = "Pass";
            disableInputForPass = true;
            StartCoroutine(Next());

            IEnumerator Next()
            {
                yield return(new WaitForSeconds(2.0f));

                indicatorText.text  = "";
                disableInputForPass = false;
            }

            PassTurn();
            return(null);
        }
    }
Esempio n. 2
0
    private void ShowPossibleLocation(GridBox.Status color)
    {
        ClearIndicObjs();

        for (var i = 0; i < 8; i++)
        {
            for (var j = 0; j < 8; j++)
            {
                List <GridBox> dummy;
                if (CheckPieceValid(color, new Index(i, j), out dummy))
                {
                    var v    = IndexToVector2(new Index(i, j));
                    var indc = Instantiate(indcObj, new Vector3(v.x, v.y, -1), Quaternion.identity);
                    indicObjs.Add(indc);
                }
            }
        }

        if (indicObjs.Count == 0)
        {
            if (blackPieces.Count + whitePieces.Count == 8 * 8)
            {
                if (blackPieces.Count < whitePieces.Count)
                {
                    indicatorText.text = "White Win";
                }
                else if (blackPieces.Count > whitePieces.Count)
                {
                    indicatorText.text = "Black Win";
                }
                else
                {
                    indicatorText.text = "Drew";
                }

                isGameEnd = true;

                return;
            }

            indicatorText.text  = "Pass";
            disableInputForPass = true;
            StartCoroutine(Next());

            IEnumerator Next()
            {
                yield return(new WaitForSeconds(2.0f));

                indicatorText.text  = "";
                disableInputForPass = false;
            }

            PassTurn();
        }
    }
Esempio n. 3
0
    public bool CheckPieceValid(GridBox.Status color, Index index, out List <GridBox> revList, bool execute = false)
    {
        revList = new List <GridBox>();

        if (matrix.GetGrid(index).GetStat() != GridBox.Status.None)
        {
            return(false);
        }

        var pieceList       = GetCrossPieces(index);
        var sameColorPieces = pieceList.Where(piece => piece.GetStat() == color);
        var able            = false;

        foreach (var piece in sameColorPieces)
        {
            if (IsAdjacent(index, piece.GetIndex()))
            {
                continue;
            }

            var crossList      = GetCrossPieces(index, piece.GetIndex(), false);
            var revColorPieces = crossList.Where(p => p.GetStat() == (GridBox.Status)((int)color * -1));
            var b = crossList.Any(p => p.GetStat() == GridBox.Status.None || p.GetStat() == color);

            if (revColorPieces.Count() != 0 && !b)
            {
                if (execute)
                {
                    foreach (var revColorPiece in revColorPieces)
                    {
                        revColorPiece.Flip();
                        if (revColorPiece.GetStat() == GridBox.Status.Black)
                        {
                            blackPieces.Add(revColorPiece.piece);
                            whitePieces.Remove(revColorPiece.piece);
                        }
                        else
                        {
                            whitePieces.Add(revColorPiece.piece);
                            blackPieces.Remove(revColorPiece.piece);
                        }

                        UpdateCountUI();
                    }
                }

                revList.AddRange(revColorPieces);

                able = true;
            }
        }

        return(able);
    }
Esempio n. 4
0
    public void SetColor(GridBox.Status color)
    {
        Start();

        if (color == GridBox.Status.Black)
        {
            SR.sprite = BlackSprite;
        }
        else if (color == GridBox.Status.White)
        {
            SR.sprite = WhiteSprite;
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
Esempio n. 5
0
    public void FlipAnim(GridBox.Status to)
    {
        if (to == GridBox.Status.Black)
        {
            var curIndex = -1;

            isAnimating = true;
            StartCoroutine(Next());
            IEnumerator Next()
            {
                yield return(new WaitForSeconds(flipInterval));

                curIndex++;
                SR.sprite = FlipSprites[curIndex];

                if (curIndex < 8)
                {
                    StartCoroutine(Next());
                }

                isAnimating = false;
            }
        }
        else
        {
            var curIndex = 9;

            isAnimating = true;
            StartCoroutine(Next());
            IEnumerator Next()
            {
                yield return(new WaitForSeconds(flipInterval));

                curIndex--;
                SR.sprite = FlipSprites[curIndex];

                if (curIndex > 0)
                {
                    StartCoroutine(Next());
                }

                isAnimating = false;
            }
        }
    }
Esempio n. 6
0
    public void Execute(GridBox.Status comColor)
    {
        var possibleLocs = GameMode.Instance.GetPossibleLocation(comColor);

        var max         = -100;
        var selectedLoc = new Tuple <int, int>(-1, -1);

        foreach (var loc in possibleLocs)
        {
            int placedVal = 0;

            try
            {
                placedVal = gridWeight[loc.Item1][loc.Item2];
            }
            catch (ArgumentOutOfRangeException)
            {
                Debug.LogError("Index Error! / " + loc.ToString());
                placedVal = 0;
            }

            var flipedSumVal = 0;

            List <GridBox> flipedList;
            GameMode.Instance.CheckPieceValid(comColor, loc, out flipedList, false);

            foreach (var fp in flipedList)
            {
                var fp_index  = fp.GetIndex();
                var fp_weight = gridWeight[fp_index.Item1][fp_index.Item2];

                flipedSumVal += fp_weight + 10;
            }

            var score = placedVal + flipedSumVal;

            if (score > max)
            {
                max         = score;
                selectedLoc = loc;
            }
        }

        GameMode.Instance.PlacePiece(comColor, selectedLoc);
    }
Esempio n. 7
0
    public void PlacePiece(GridBox.Status playerColor, Index index, bool isStatic = false)
    {
        List <GridBox> dummy;

        if (!CheckPieceValid(playerColor, index, out dummy, true) && !isStatic)
        {
            return;
        }

        Vector3 pos = IndexToVector2(index);

        pos.z = -1;

        var obj = Instantiate(pieceObj, pos, Quaternion.identity);

        obj.name = index.Item1 + " / " + index.Item2;

        var grid  = matrix.GetGrid(index);
        var piece = obj.GetComponent <Piece>();

        grid.SetStat(playerColor);
        grid.SetPiece(piece);

        piece.SetParentGrid(grid);
        piece.SetColor(playerColor);

        if (playerColor == GridBox.Status.Black)
        {
            blackPieces.Add(piece);
        }
        else
        {
            whitePieces.Add(piece);
        }

        UpdateCountUI();

        if (isStatic)
        {
            return;
        }

        PassTurn();
    }