Example #1
0
 public CommandFormat(CommandAckStruct cmd, ActionStruct action, byte[] payload)
 {
     CommandAck = cmd;
     Action     = action;
     Payload    = new byte[10];
     payload.CopyTo(Payload, 0);
 }
 public void Attack(ActionStruct action, BoardController boardController)
 {
     if (action.type == ActionType.melee)
     {
         Debug.Log($"{_tokken.posOnBoardX}, {_tokken.posOnBoardY}, {action.direction}, {_tokken.faction}");
         Tokken target = boardController.CheckForFirstTargetInLine(_tokken.posOnBoardX, _tokken.posOnBoardY, action.direction, 1, _tokken.faction);
         if (target != null)
         {
             Debug.Log($"Atakujo");
             Debug.Log($"{target.name}");
             target.GetComponent <IDamage>().TakeDamage(action.damage);
         }
         else
         {
             Debug.Log("Brak targetu");
         }
     }
     if (action.type == ActionType.ranged)
     {
         Tokken target = boardController.CheckForFirstTargetInLine(_tokken.posOnBoardX, _tokken.posOnBoardY, action.direction, 5, _tokken.faction);
         if (target != null)
         {
             target.GetComponent <IDamage>().TakeDamage(action.damage);
         }
     }
 }
Example #3
0
 public CommandFormat(byte cmd, byte action, byte[] payload)
 {
     CommandAck = new CommandAckStruct(cmd);
     Action     = new ActionStruct(action);
     Payload    = new byte[10];
     payload.CopyTo(Payload, 0);
 }
        public static ActionStruct ConvertInputToActionStruct(String str)
        {
            String[] parts = str.Split(':');

            ActionStruct actionStruct = new ActionStruct(parts[0], parts[2].Split(','), ConvertStringToActionType(parts[1]));

            return(actionStruct);
        }
Example #5
0
    public void SaveInStack(Entity instance, float _rotationY)
    {
        var temp = new ActionStruct();

        temp.entity    = instance;
        temp.type      = ActionType.rot;
        temp.rotationY = _rotationY;
        PushAction(temp);
    }
Example #6
0
        private void ProcessSYSEX(byte[] readBuffer, int dataLength)
        {
            ActionStruct a = new ActionStruct();

            byte[] data = new byte[dataLength - 1]; //readBuffer;
            Array.Copy(readBuffer, 1, data, 0, dataLength - 1);
            DebugPrint("ProcessSYSEX...\r\n");      //?????????????????

            uint seq            = (uint)data[0] >> 6;
            uint idx            = (uint)data[0] & 0x3F;
            uint data_length    = (uint)data[1] << 1 | ((uint)data[2] >> 7);
            uint manufacture_ID = (((uint)data[2]) & 0x7F) << 4 | ((uint)data[3] >> 4);
            uint fn_number      = ((uint)data[3] & 0x0F) << 8 | data[4];
            uint Data           = data[5];

            byte[] fromId = new byte[4];
            Array.Copy(data, 9, fromId, 0, 4);
            byte[] destId = new byte[4];
            Array.Copy(readBuffer, dataLength + 1, destId, 0, 4);

            if ((RMC)fn_number == RMC.QueryID || (RMC)fn_number == RMC.Ping)
            {
                a.action      = Action.AnswerRMC;
                a.destination = fromId;
                a.parameter   = new byte[] { (byte)fn_number };
                EnqueueAndSet(a);
            }
            else if (manufacture_ID == manufactureID && (RMC)fn_number == RMC.RPCRepeater && destId != Tx.broadcast)
            {
                switch (Data)
                {
                case 0x0A:
                    a.action      = Action.ReadRepeater;
                    a.destination = fromId;
                    a.parameter   = new byte[] { 0 };
                    EnqueueAndSet(a);
                    break;

                case 0x00:
                case 0x01:
                case 0x02:
                    a.action      = Action.WriteRepeater;
                    a.destination = fromId;
                    a.parameter   = new byte[] { (byte)Data };
                    EnqueueAndSet(a);
                    break;

                default:
                    a.action      = Action.TransmitError;
                    a.destination = fromId;
                    a.parameter   = new byte[] { (byte)0xE0 };
                    EnqueueAndSet(a);
                    break;
                }
            }
        }
Example #7
0
    public void SaveInStack(Entity instance, float posX, float posY)
    {
        var temp = new ActionStruct();

        temp.entity = instance;
        temp.type   = ActionType.pos;
        temp.x      = posX;
        temp.y      = posY;
        PushAction(temp);
    }
 public void TriggerBattleActions(BoardController boardController)
 {
     for (int i = 0; i < actions.Count; i++)
     {
         ActionStruct action = actions[i];
         if (action.type == ActionType.melee || action.type == ActionType.ranged)
         {
             Attack(action, boardController);
         }
     }
 }
Example #9
0
 private void UpdateReward2(ActionStruct _actstr, double _reward)
 {
     if (_actstr.samples == 0)
     {
         _actstr.expectation = _reward;
     }
     else
     {
         _actstr.expectation = (_actstr.expectation + _reward) / 2;
     }
     _actstr.samples++;
 }
Example #10
0
        // The beef: return an optimal action when we know the state
        public Action SelectAction(State _state)
        {
            // Find corresponding state struct
            StateStruct found = null;

            foreach (StateStruct statestr in states)
            {
                if (def.IsSameState(statestr.state, _state))
                {
                    found = statestr;
                    break;
                }
            }
            // If not found, we have a new state, let's add that
            if (found == null)
            {
                found = new StateStruct(_state, def);
                states.Add(found);
            }

            // Then select either the best action (exploit) or some other (explore)
            ActionStruct selected = null;

            if (rnd.NextDouble() < 0.1)
            {
                // Select random
                int inx = rnd.Next(found.actions.Count());
                selected = found.actions.ElementAt(inx);
            }
            else
            {
                // Select the best
                selected = found.actions.ElementAt(0);
                foreach (ActionStruct actstr in found.actions)
                {
                    if (actstr.expectation > selected.expectation)
                    {
                        //if (actstr.expectation > selected.expectation || (actstr.expectation == selected.expectation && rnd.NextDouble() < 0.2)) // add some randomness if there are several similar options
                        selected = actstr;
                    }
                }
            }

            // Remember last selected actions (4 of them)
            if (last_actions.Count >= 4)
            {
                last_actions.RemoveAt(0);
            }
            last_actions.Add(selected);

            return(selected.action);
        }
Example #11
0
        //
        //
        //
        public void ActionThread()
        {
            Random random = new Random(456);

            while (true)
            {
                actionEvent.WaitOne();
                if (actionQueue.Count == 0)
                {
                    Thread.Sleep(33);
                    continue;
                }
                ActionStruct a = (ActionStruct)actionQueue.Dequeue();
                //DebugPrint("Action: " + a.action.ToString() + "\r\n"); //??????????????????????????
                switch (a.action)
                {
                case Action.TransmitPower:
                    TransmitPower();
                    break;

                case Action.SetVersion:
                    SetVersion(a.parameter);
                    break;

                case Action.TransmitResponse:
                    TransmitResponse(a.parameter[0], a.destination);
                    break;

                case Action.ReadRepeater:
                    ReadRepeater(a.destination);
                    break;

                case Action.WriteRepeater:
                    WriteRepeater(a.parameter[0], a.destination);
                    break;

                case Action.AnswerRMC:
                    AnswerRMC(a.parameter[0], a.destination);
                    break;

                case Action.TransmitError:
                    TransmitError(a.parameter[0], a.destination);
                    break;

                default:
                    break;
                }
                System.Threading.Thread.Sleep(random.Next(50) + 5); // 5 - 50msec
            }
        }
    public void CalculateResult_enemy()
	{
        if (player.hp > 0 && enemy.hp > 0)
		{
            player.hp -= enemy.dmg;
            ActionStruct thisAction = new ActionStruct();
            thisAction.dmgInflicted = enemy.dmg;
            thisAction.inflicter = enemy.namae;
            thisAction.inflictee = "you";
            actions.Add(thisAction);
            print(thisAction.inflicter + " did " + thisAction.dmgInflicted + " damage to " + thisAction.inflictee);
            if (player.hp <= 0)
            {
                ActionStruct deathAction = new ActionStruct();
                deathAction.deathText = "You are dead";
                actions.Add(deathAction);
                print("the player is dead");
            }
        }
	}
    public void CalculateResult_player(int whichItemPlayersUsing)
	{
        // player attack
        if (itemsPlayersUsing.Count > 0)
		{
            if (itemsPlayersUsing[whichItemPlayersUsing].durability > 0 && enemy.hp > 0 && player.hp > 0)
            {
                int dmgInflicted = itemsPlayersUsing[whichItemPlayersUsing].dmg;
                if (itemsPlayersUsing[whichItemPlayersUsing].blunt)
                {
                    dmgInflicted += enemy.dp * bluntFactor;
                }
                if (itemsPlayersUsing[whichItemPlayersUsing].sharp)
                {
                    dmgInflicted += enemy.sp * sharpFactor;
                }
                if (itemsPlayersUsing[whichItemPlayersUsing].fire)
                {
                    dmgInflicted += enemy.AoF * fireFactor;
                }
                if (itemsPlayersUsing[whichItemPlayersUsing].aoe)
                {
                    dmgInflicted += enemy.AoAOE * aoeFactor;
                }
                enemy.hp -= dmgInflicted;
                itemsPlayersUsing[whichItemPlayersUsing].durability--;
                ActionStruct thisAction = new ActionStruct();
                thisAction.dmgInflicted = dmgInflicted;
                thisAction.inflicter = "You";
                thisAction.inflictee = enemy.namae;
                actions.Add(thisAction);
                print(thisAction.inflicter + " did " + thisAction.dmgInflicted + " damage to " + thisAction.inflictee);
                if (enemy.hp <= 0)
                {
                    ActionStruct deathAction = new ActionStruct();
                    deathAction.deathText = enemy.namae + " is dead";
                    actions.Add(deathAction);
                    print(enemy.namae + " is dead");
                }
                if (itemsPlayersUsing[whichItemPlayersUsing].durability <= 0)
                {
                    ActionStruct itemAction = new ActionStruct();
                    itemAction.itemText = itemsPlayersUsing[whichItemPlayersUsing].namae + " is broken\n";
                    actions.Add(itemAction);
                    print("item broke");
                    itemsPlayersUsing.RemoveAt(whichItemPlayersUsing);
                }
            }
        }
		else // if player isn't using any items(bare hands)
		{
            if (enemy.hp > 0 && player.hp > 0)
			{
                enemy.hp -= 1;
                ActionStruct thisAction = new ActionStruct();
                thisAction.dmgInflicted = 1;
                thisAction.inflicter = "You";
                thisAction.inflictee = enemy.namae;
                actions.Add(thisAction);
                print(thisAction.inflicter + " did " + thisAction.dmgInflicted + " damage to " + thisAction.inflictee);
                if (enemy.hp <= 0)
                {
                    ActionStruct deathAction = new ActionStruct();
                    deathAction.deathText = enemy.namae + " is dead";
                    actions.Add(deathAction);
                    print(enemy.namae + " is dead");
                }
            }
		}
	}
Example #14
0
 private void EnqueueAndSet(ActionStruct a)
 {
     actionQueue.Enqueue(a);
     actionEvent.Set();
 }
Example #15
0
 void PushAction(ActionStruct temp)
 {
     temp.isMain = temp.entity.GetType() == Type.GetType("Boat");
     _actionStack.Push(temp);
 }
Example #16
0
 public CommandFormat(CommandAckStruct cmd, ActionStruct action, byte[] payload)
 {
     CommandAck = cmd;
     Action = action;
     Payload = new byte[10];
     payload.CopyTo(Payload, 0);
 }
Example #17
0
 public CommandFormat(byte cmd, byte action, byte[] payload)
 {
     CommandAck = new CommandAckStruct(cmd);
     Action = new ActionStruct(action);
     Payload = new byte[10];
     payload.CopyTo(Payload, 0);
 }
Example #18
0
 public CommandFormat(CommandAckStruct cmd, ActionStruct action)
 {
     CommandAck = cmd;
     Action = action;
     Payload = new byte[10];
 }
Example #19
0
 public CommandFormat(byte cmd, byte action)
 {
     CommandAck = new CommandAckStruct(cmd);
     Action     = new ActionStruct(action);
     Payload    = new byte[10];
 }
Example #20
0
        public override void Update(GameTime gameTime)
        {
            double elapsedCutsceneTime = Environment.TickCount - timeStoryElementStarted;

            #region audio
            AudioElement audio = Game.instance.storyElement.popAudioElement(elapsedCutsceneTime);
            if (audio != null)
            {
                Game.instance.Content.Load <SoundEffect>(Game.instance.mapManager.currentCampaignPath + audio.audioPath).Play();
            }
            #endregion
            #region characters
            foreach (BeingController controller in Game.instance.storyElement.beingControllers)
            {
                if (!storyBeings.ContainsKey(controller.entranceMS) &&
                    controller.entranceMS >= elapsedCutsceneTime)
                {
                    Being being = new Being(controller.entranceMS + "", 1, controller.animationController, null, false, true);
                    being.body.Position = controller.startLocation;
                    being.changeAnimation(controller.animations[0].animationName);
                    being.setDepth(controller.startDepth);
                    storyBeings.Add(controller.entranceMS, being);
                }
                if (storyBeings.ContainsKey(controller.entranceMS))
                {
                    Being being = storyBeings[controller.entranceMS];
                    being.changeAnimation(controller.getCurrentAnimation(elapsedCutsceneTime));
                    ActionStruct currentAction = controller.getCurrentAction(elapsedCutsceneTime);
                    if (currentAction != null)
                    {
                        switch (currentAction.action)
                        {
                        case ActionEnum.Jump:
                            being.jump();
                            break;

                        case ActionEnum.Stop:
                            being.body.ApplyForce(-being.body.Force);
                            break;

                        case ActionEnum.Move:
                            being.move(new Vector2(currentAction.intensity, 0));
                            break;
                        }
                    }
                }
            }
            foreach (Being being in storyBeings.Values)
            {
                being.update(gameTime);
            }
            #endregion
            #region quit cutscene
            bool skip = false;
            foreach (Being player in Game.instance.players.Values)
            {
                if (player.isLocal && (player.input.getButtonHit(Buttons.Start) || player.input.getButtonHit(Buttons.Back)))
                {
                    skip = true;
                }
            }
            if (skip || Game.instance.storyElement.cutsceneLength + 500 < Environment.TickCount - timeStoryElementStarted)
            {
                Game.instance.currentState.setState(GameState.Gameplay);
                Game.instance.storyElement = null;
                storyBeings.Clear();
            }
            #endregion
            #region Physics
            if (previousGameTime == null)
            {
                previousGameTime = gameTime;
            }
            float timeElapsed = (float)gameTime.TotalGameTime.TotalMilliseconds - (float)previousGameTime.TotalGameTime.TotalMilliseconds;
            Game.instance.physicsSimulator.Update((timeElapsed > .1f) ? timeElapsed : .1f);
            previousGameTime = gameTime;
            #endregion
        }
Example #21
0
 void OnClickListener(object sender, RoutedEventArgs e)
 {
     this._param.Dependency._reactor.action.OnNext(ActionStruct.Dispatcher(ActionStruct.Action.didLoad));
 }
Example #22
0
 public CommandFormat(CommandAckStruct cmd, ActionStruct action)
 {
     CommandAck = cmd;
     Action     = action;
     Payload    = new byte[10];
 }
Example #23
0
 public CommandFormat(byte cmd, byte action)
 {
     CommandAck = new CommandAckStruct(cmd);
     Action = new ActionStruct(action);
     Payload = new byte[10];
 }
Example #24
0
        // After action selection, we will get the immediate reward
        public void EarnReward(double _reward, int _offset)
        {
            // Depending if AI is playing one or two roles, update last or second last
            ActionStruct actstr = null;

            if (player_number == PlayerNumberEnum.AI_PLAYS_SINGLE && last_actions.Count() >= 1)
            {
                actstr = last_actions.ElementAt(last_actions.Count() - 1);
            }
            if (player_number == PlayerNumberEnum.AI_PLAYS_BOTH && last_actions.Count() >= _offset)
            {
                actstr = last_actions.ElementAt(last_actions.Count() - _offset);
            }
            if (actstr == null)
            {
                return;
            }

            UpdateReward1(actstr, _reward);

            // And, if there is also the previous action, update that too (because choosing that one led to this reward)
            ActionStruct prev_actstr = null;

            if (player_number == PlayerNumberEnum.AI_PLAYS_SINGLE && last_actions.Count() >= 2)
            {
                prev_actstr = last_actions.ElementAt(last_actions.Count() - 2);
            }
            if (player_number == PlayerNumberEnum.AI_PLAYS_BOTH && last_actions.Count() >= (_offset + 2))
            {
                prev_actstr = last_actions.ElementAt(last_actions.Count() - (_offset + 2));
            }
            if (prev_actstr == null)
            {
                return;
            }

            // Calculate the combined reward for previous layer

/*            double reward = 0;
 *          int samples = 0;
 *          foreach (ActionStruct it in actstr.parent.actions)
 *          {
 *              if (it.samples > 0)
 *              {
 *                  reward += it.expectation;
 *                  samples++;
 *              }
 *          }
 *          if (samples > 0)
 *          {
 *              reward /= samples;
 *              UpdateReward1(prev_actstr, reward);
 *          }
 */
            double reward  = 0;
            int    samples = 0;

            foreach (ActionStruct it in actstr.parent.actions)
            {
                if ((samples == 0 && it.samples > 0) || (it.samples > 0 && it.expectation > reward))
                {
                    reward = it.expectation;
                    samples++;
                }
            }
            UpdateReward1(prev_actstr, reward);
        }
Example #25
0
        private void ProcessResponse(byte[] readBuffer, int dataLength)
        {
            /*            +-----------------------------------------------+ */
            /*            |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  | */
            /*            +-----------------------------------------------+ */
            /*            |SYNCBYTE1(0xA5)                                | */
            /*            +-----------------------------------------------+ */
            /*            |SYNCBYTE0(0x5A)                                | */
            /*            +-----------------------------------------------+ */
            /*                                                              */
            /*            +-----------------------------------------------+ */
            /*            |HSEQ             |LENGTH                       | */
            /*            +-----------------------------------------------+ */
            /*            |ORG                                            | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*            |                                               | */
            /*            +-----------------------------------------------+ */
            /*                                                              */
            /*            +-----------------------------------------------+ */
            /*            |CHECKSUM                                       | */
            /*            +-----------------------------------------------+ */

            ActionStruct a = new ActionStruct();

            //DebugPrint("ProcessResponse...\r\n"); //?????????????????

            if (dataLength > 4)
            {
                Array.Copy(readBuffer, 1, AppVersion, 0, 4);
            }
            if (dataLength > 8)
            {
                Array.Copy(readBuffer, 5, APIVersion, 0, 4);
            }
            if (dataLength > 12)
            {
                Array.Copy(readBuffer, 9, myID, 0, 4);
            }
            if (dataLength > 16)
            {
                Array.Copy(readBuffer, 13, ChipVersion, 0, 4);
            }
            if (dataLength > 32)
            {
                byte[] appDescArray = new byte[16];
                Array.Copy(readBuffer, 13, appDescArray, 0, 16);
            }

            while (responseQueue.Count == 0)
            {
                Thread.Sleep(61);
            }

            ResponseStruct res     = (ResponseStruct)responseQueue.Dequeue();
            int            resCode = (int)readBuffer[0];

            a.action    = Action.NoAction;
            a.parameter = new byte[] { 0 };

            switch (res.r)
            {
            case Transmit.Response.Teachin:
                a.action = Action.TransmitPower;
                EnqueueAndSet(a);
                break;

            case Transmit.Response.GetVersion:
                a.action    = Action.SetVersion;
                a.parameter = readBuffer;
                EnqueueAndSet(a);
                break;

            case Transmit.Response.ReadRepeater:
                if (resCode == 0)
                {
                    a.action      = Action.TransmitResponse;
                    a.parameter   = new byte[] { (byte)((readBuffer[1] | readBuffer[1] << 1) & readBuffer[2]) };
                    a.destination = res.destination;
                    EnqueueAndSet(a);
                }
                else
                {
                    a.action      = Action.TransmitError;
                    a.parameter   = new byte[] { (byte)(0xE0 | resCode) };
                    a.destination = res.destination;
                    EnqueueAndSet(a);
                }
                break;

            case Transmit.Response.WriteRepeater:
                if (resCode == 0)
                {
                    a.action      = Action.ReadRepeater;
                    a.destination = res.destination;
                    EnqueueAndSet(a);
                }
                else
                {
                    a.action      = Action.TransmitError;
                    a.parameter   = new byte[] { (byte)(0xF0 | resCode) };
                    a.destination = res.destination;
                    EnqueueAndSet(a);
                }
                break;

            //case Transmit.Response.Data4BS:
            //case Transmit.Response.DataRPS:
            //case Transmit.Response.Data1BS:
            //case Transmit.Response.SYS_EX:
            //case Transmit.Response.RemoteManagement:
            default:
                break;
            }
        }
Example #26
0
 void PageLoaded(object sender, RoutedEventArgs e)
 {
     Debug.WriteLine("PageLoaded Main");
     this._param.Dependency._reactor.action.OnNext(ActionStruct.Dispatcher(ActionStruct.Action.didLoad));
 }
Example #27
0
 public void Do()
 {
     Type         type = typeof(ActionStruct).MakeGenericType(typeof(ActionStruct));
     ActionStruct obj  = (ActionStruct)Activator.CreateInstance(type);
 }