日報(6/1)

今日やったこと

ワーキングメモリーレーニン

鬼ネズミ、計算20、計算100。

Lv.11のみ120問程度。

力学

人気ゲーム分析

  • キミガシネ

ゲーム開発

ゲームの状態遷移図

ゲームの状態遷移図はこんな感じです。

f:id:alberto_hojo:20190601134502p:plain

GameStete.csの作成

namespace Manager
{
    public enum GameState
    {
        Home,
        Start,
        Play,
        Result,
        Pause
    }
}

GameStateManagerクラスの作成

前回同様、UniRxのReactivePropertyで管理します。

このクラスはシングルトンになります。

このクラスが必要になった時に、Zenjectを使って各クラスに代入します。

using UniRx;

namespace Manager
{
    public class GameStateManager
    {
        //GameState.Homeで初期化
        private ReactiveProperty<GameState> currentGameState = new ReactiveProperty<GameState>(GameState.Home);

        public IReadOnlyReactiveProperty<GameState> CurrentGameState => currentGameState;

        public GameState GameState => currentGameState.Value;

        //状態を変更
        public void SetGameState(GameState state)
        {
            currentGameState.Value = state;
        }
    }
}

Zenjectを使うのでMonoInstallerを継承しているSceneInstallerを作成します。

using UnityEngine;
using Zenject;

namespace Manager
{
    public class SceneInstaller : MonoInstaller
    {
        public override void InstallBindings()
        {
            Container
                .Bind<GameStateManager>()
                .AsSingle();
        }
    }
}

RobotAgentクラスの変更

Zenjectを導入し、GameStateManagerクラスを作成したので、これらに伴いRobotAgentクラスを変更します。

using UnityEngine;
using MLAgents;
using Manager;
using Zenject;

public class RobotAgent : Agent
{
    private Rigidbody rb;

    private Vector3 forceDirection;

    [SerializeField] private float force;

    [Inject] private GameStateManager gameStateManager;

    private void Start()
    {
        rb = this.GetComponent<Rigidbody>();
    }

    public override void CollectObservations()
    {
        AddVectorObs(this.transform.localPosition);
        AddVectorObs(this.rb.velocity);
    }

    public override void AgentAction(float[] vectorAction, string textAction)
    {
        if (gameStateManager.GameState != GameState.Play)
            return;

        forceDirection.x = vectorAction[0];
        forceDirection.z = vectorAction[1];

        rb.AddForce(forceDirection * force);
    }

    public override void AgentReset()
    {

    }
}

Playerの状態遷移図

f:id:alberto_hojo:20190601223342p:plain:w250

PlayerState列挙体の作成

namespace Manager
{
    public enum PlayerState
    {
        Idle,
        Move,
        Collapse
    }
}

PlayerStateManagerの作成

GameStateManagerと同様にReactivePropertyで管理します。

using UniRx;

namespace Manager
{
    public class PlayerStateManager
    {
        //PlayerState.Idleで初期化
        private ReactiveProperty<PlayerState> currentPlayerState = new ReactiveProperty<PlayerState>(PlayerState.Idle);

        public IReadOnlyReactiveProperty<PlayerState> CurrentPlayerState => currentPlayerState;

        public PlayerState PlayerState => currentPlayerState.Value;

        //状態を変更
        public void SetPlayerState(PlayerState state)
        {
            currentPlayerState.Value = state;
        }
    }
}

これに伴って勿論SceneInstallerにも変更を加えます。

using UnityEngine;
using Zenject;

namespace Manager
{
    public class SceneInstaller : MonoInstaller
    {
        public override void InstallBindings()
        {
            Container
                .Bind<GameStateManager>()
                .AsSingle();

            Container
                .Bind<PlayerStateManager>()
                .AsSingle();
        }
    }
}

今日のパフォーマンス

JINS MEME ESという最新の学術研究の成果を元に人間の心理状態を測定できるウェアラブルバイスを使って本日の僕の集中状態を測定した結果は以下のようになりました。

f:id:alberto_hojo:20190601234851p:plain:w250

作業時間 8時間48分

集中時間 3時間11分

集中率 36 %

反省

なんだか最近パッとしない感じがします。

休息が足りていないことが原因な気がするので、明日は思い切って半日休みにしようかと思っています。