Exemplo n.º 1
0
        private void OnReceivedAction(TurnAction action)
        {
            bool validAction = false;

            if (action.components.Count == 1 && action.components[0].type == TurnActionComponentType.Forfeit)
            {
                validAction = true;
            }
            else
            {
                int pieceIndex = board.PieceOnSpace(action.searchPiece);
                if (pieceIndex >= 0)
                {
                    TurnOptions currentOptions = turnOptionCalculator.Send(new TurnOptionCalculatorArgs()
                    {
                        pieceIndex = pieceIndex,
                        luaState   = LuaTranslator.GetMoveCalcState(pieceIndex, board, db),
                    });
                    foreach (var possible in currentOptions.options)
                    {
                        if (possible.IsEquivalent(action))
                        {
                            validAction = true;
                            break;
                        }
                    }
                }
            }
            if (!validAction)
            {
                UnityEngine.Debug.LogError("Cheating detected! Or at least a mod mismatch!");
            }
            choiceMadeEvent.Send(action);
        }
        private bool Calculate(CheckCalcArgs args)
        {
            Piece king = board.Pieces[args.kingIndex];

            for (int p = 0; p < board.Pieces.Count; p++)
            {
                Piece enemy = board.Pieces[p];
                if (enemy.OwnerPlayer != king.OwnerPlayer)
                {
                    TurnOptions moveOptions = moveOptionQuery.Send(new TurnOptionCalculatorArgs()
                    {
                        pieceIndex = p,
                        luaState   = LuaTranslator.GetMoveCalcState(p, board, db),
                    });
                    foreach (var option in moveOptions.options)
                    {
                        if (option.components[0].target == args.testPosition)
                        {
                            BalugaDebug.Log(string.Format("King {0} in check from {1} at {2}", args.kingIndex, p, enemy.BoardPosition));
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        private void RefreshMoveOptions()
        {
            int pieceID = -1;

            switch (selEvent.CurrentType)
            {
            case PlayerSelectionEvent.SelectionType.Piece:
                pieceID = selEvent.PieceID;
                break;

            case PlayerSelectionEvent.SelectionType.Square:
                pieceID = board.PieceOnSpace(selEvent.SquarePos);
                break;
            }
            if (pieceID >= 0 && pieceID != chosenPiece.Value)
            {
                Piece       piece             = board.Pieces[pieceID];
                TurnOptions calculatedOptions = moveOptionCalculator.Send(new TurnOptionCalculatorArgs()
                {
                    pieceIndex = pieceID,
                    luaState   = LuaTranslator.GetMoveCalcState(pieceID, board, db),
                });

                displayMessage.Send(compiler.Send(new ActionIndicatorPatternCompileArgs()
                {
                    options          = calculatedOptions,
                    highlightedIndex = -1,
                    mouseOverMode    = true,
                }));
            }
            else
            {
                displayMessage.Send(null);
            }
        }
Exemplo n.º 4
0
        private EoTScriptState CheckGameOver()
        {
            EoTScriptState type = EoTScriptState.Undecided;

            NextTurnInfo nextTurn = nextTurnInfo.Send();

            lastCalcState.TurnInfo = LuaTranslator.GetTurnInfo(nextTurn);
            lastCalcState.Board    = LuaTranslator.GetBoard(board, db);

            luaHelper.Ready = true;
            scripts.AddGlobal("winCheckHelper", luaHelperValue);
            DynValue ret = scripts.CallFunction(db.WinLossCheck, lastCalcState.Board);

            scripts.RemoveGlobal("winCheckHelper");
            luaHelper.Ready = false;

            foreach (var options in optionCache.Values)
            {
                options.Dispose();
            }
            optionCache.Clear();

            if (ret.Type != DataType.String)
            {
                type = EoTScriptState.Error;
            }
            else
            {
                switch (ret.String.ToUpperInvariant())
                {
                case Mods.Lua.LuaConstants.GameOverFirstWins:
                    type = EoTScriptState.FirstPlayerWins;
                    break;

                case Mods.Lua.LuaConstants.GameOverSecondWins:
                    type = EoTScriptState.SecondPlayerWins;
                    break;

                case Mods.Lua.LuaConstants.GameOverTie:
                    type = EoTScriptState.Tie;
                    break;

                case Mods.Lua.LuaConstants.GameOverUndecided:
                    type = EoTScriptState.Undecided;
                    break;

                default:
                    type = EoTScriptState.Error;
                    break;
                }
            }

            return(type);
        }
Exemplo n.º 5
0
        private bool CheckHasPieces(string player)
        {
            PlayerTurnOrder turnOrder = LuaTranslator.GetPlayerFromLua(player);

            for (int p = 0; p < board.Pieces.Count; p++)
            {
                Piece piece = board.Pieces[p];
                if (!piece.IsCaptured && piece.OwnerPlayer == turnOrder)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        private bool CheckCanMove(string player)
        {
            PlayerTurnOrder turnOrder = LuaTranslator.GetPlayerFromLua(player);

            for (int p = 0; p < board.Pieces.Count; p++)
            {
                Piece piece = board.Pieces[p];
                if (!piece.IsCaptured && piece.OwnerPlayer == turnOrder)
                {
                    PieceTurnOptions luaOptions = CacheTurnOptions(p);
                    if (CheckTurnOptionsHasAny(luaOptions))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 7
0
 private void OnEnterState(int state)
 {
     if (chooserState.State == (int)TurnChooser.State.ChooseAction)
     {
         chosenAction.Value = null;
         inputOffsets.Clear();
         currentOptions = turnOptionCalculator.Send(new TurnOptionCalculatorArgs()
         {
             pieceIndex = chosenPiece.Value,
             luaState   = LuaTranslator.GetMoveCalcState(chosenPiece.Value, board, db),
         });
         RefreshHighlightedValue();
     }
     else
     {
         highlightMessage.Send(new TurnChooserHighlight()
         {
             options          = null,
             indexesOnSpace   = null,
             highlightedIndex = -1,
         });
         currentOptions = null;
     }
 }