Exemple #1
0
 public void RunMove(BoardCoordinator board)
 {
     foreach (SpecialResult res in results)
     {
         res.Modify(board);
     }
 }
Exemple #2
0
    public bool Check(BoardCoordinator board)
    {
        switch (type)
        {
        case SpecialConditionCheckType.HASMOVED:
        case SpecialConditionCheckType.HASNOTMOVED:
            bool?tmp = board.DidPieceMoved(cell);
            if (type == SpecialConditionCheckType.HASNOTMOVED)
            {
                tmp = !tmp;
            }
            return(tmp ?? false);

        case SpecialConditionCheckType.ISPIECE:
            try
            {
                return(board.GetPieceFromCell(cell).GetCharacter() == piece);
            }
            catch
            {
                return(false);
            }

        case SpecialConditionCheckType.ISPLAYER:
            try
            {
                return(board.GetPieceFromCell(cell).GetPlayer() == player);
            }
            catch
            {
                return(false);
            }

        case SpecialConditionCheckType.ISTEAM:
            try
            {
                return(board.GetPieceFromCell(cell).GetTeam() == player);
            }
            catch
            {
                return(false);
            }

        case SpecialConditionCheckType.ISEMPTY:
            return(board.GetPieceFromCell(cell) == null);

        case SpecialConditionCheckType.ISNOTEMPTY:
            return(board.GetPieceFromCell(cell) != null);

        case SpecialConditionCheckType.ISATTACKED:
            return(board.IsCellUnderAttack(cell));

        case SpecialConditionCheckType.ISSAFE:
            return(!board.IsCellUnderAttack(cell));

        default:
            return(false);
        }
    }
Exemple #3
0
 public void SimulateMove(BoardCoordinator board)
 {
     board.InitSimulation();
     foreach (SpecialResult res in results)
     {
         res.Simulate(board);
     }
 }
Exemple #4
0
 public bool Check(BoardCoordinator board)
 {
     foreach (SpecialCondition cond in conditions)
     {
         if (!cond.Check(board))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #5
0
    public void Initialize()
    {
        boardCoordinator  = GameObject.FindGameObjectWithTag("BoardCoordinator").GetComponent <BoardCoordinator>();
        posiblePromotions = boardCoordinator.GetPromotablePieces();

        int maxh = Mathf.FloorToInt(Screen.height * 0.8f);
        int maxw = Mathf.FloorToInt(Screen.width * 0.8f);

        int squaresize = (maxw / 10) + 10;

        int rows = 1;

        while (Mathf.CeilToInt(posiblePromotions.Keys.Count / (rows * 1f)) * squaresize > maxw)
        {
            rows++;
        }

        int piecesPerRow = Mathf.CeilToInt(posiblePromotions.Keys.Count / (rows * 1f));
        int w            = piecesPerRow * squaresize;
        int h            = rows * squaresize;

        promotionOptionsObject.sizeDelta = new Vector2(w, h);
        backgoundImage.sizeDelta         = new Vector2(h, Screen.width);

        foreach (Transform child in rowContainer.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        char[]        pieceChars = posiblePromotions.Keys.ToArray();
        int           j = 0;
        RectTransform row, piece;

        for (int i = 0; i < rows; i++)
        {
            row           = GameObject.Instantiate(rowPrefab, rowContainer.transform).GetComponent <RectTransform>();
            row.offsetMax = new Vector2(0, -(5 + ((squaresize) * i)));    // Top-Right corner
            row.offsetMin = new Vector2(0, 5 - ((squaresize) * (i + 1))); // Bot-Left corner

            for (; (j < posiblePromotions.Keys.Count) && (j < piecesPerRow * (i + 1)); j++)
            {
                piece                  = GameObject.Instantiate(piecePrefab, row.transform).GetComponent <RectTransform>();
                piece.localScale       = new Vector3((squaresize - 10) / 100f, (squaresize - 10) / 100f);
                piece.anchoredPosition = new Vector3(5 + (squaresize * (j - (i * piecesPerRow))), 0);

                Sprite promotionSprite;
                posiblePromotions.TryGetValue(pieceChars[j], out promotionSprite);
                piece.gameObject.GetComponent <PromotionOption>().Initializate(this, pieceChars[j], promotionSprite);
            }
        }

        Hide();
    }
 public void Start()
 {
     bc = boardCoordinator.GetComponent <BoardCoordinator>();
 }
 private void Start()
 {
     sceneSwitcher = GameObject.FindGameObjectWithTag("MainLibrary").GetComponent <SceneSwitcher>();
     coordinator   = GameObject.FindGameObjectWithTag("BoardCoordinator").GetComponent <BoardCoordinator>();
 }
Exemple #8
0
 public void Simulate(BoardCoordinator board)
 {
     board.SimulateRemovePiece(where);
 }
Exemple #9
0
 public void Modify(BoardCoordinator board)
 {
     board.RemovePiece(where);
 }
Exemple #10
0
 public void Simulate(BoardCoordinator board)
 {
     board.SimulateCreatePiece(where, what);
 }
Exemple #11
0
 public void Modify(BoardCoordinator board)
 {
     board.CreatePiece(where, what);
 }
Exemple #12
0
 public void Simulate(BoardCoordinator board)
 {
     board.SimulateMovePiece(from, to);
 }
Exemple #13
0
 public void Modify(BoardCoordinator board)
 {
     board.MovePieceForced(from, to);
 }
Exemple #14
0
    public bool Check(BoardCoordinator board)
    {
        if (player != 0)
        {
            HistoryMove lastMove = board.GetLastMoveFromPlayer(player);
            if (lastMove == null)
            {
                return(false);
            }
            bool result = true;
            if (from.Length == lastMove.from.Length && to.Length == lastMove.to.Length)
            {
                for (int i = 0; i < from.Length && result; i++)
                {
                    if (from[i] != lastMove.from[i])
                    {
                        result = false;
                    }
                    if (to[i] != lastMove.to[i])
                    {
                        result = false;
                    }
                }

                return(result);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            List <HistoryMove> lastMoves = board.GetLastMoves();
            foreach (HistoryMove lastMove in lastMoves)
            {
                if (lastMove == null)
                {
                    continue;
                }
                bool result = true;
                if (from.Length == lastMove.from.Length && to.Length == lastMove.to.Length)
                {
                    for (int i = 0; i < from.Length && result; i++)
                    {
                        if (from[i] != lastMove.from[i])
                        {
                            result = false;
                        }
                        if (to[i] != lastMove.to[i])
                        {
                            result = false;
                        }
                    }
                }

                if (result)
                {
                    return(true);
                }
            }
            return(false);
        }
    }
 internal void Initialize(BoardCoordinator bc)
 {
     boardCoordinator = bc;
     ready            = true;
 }