Exemple #1
0
 private void Awake()
 {
     agent = Instantiate(agentPrefab);
     agent.Init(board, 0);
     board.newTurn  += NewTurn;
     board.gameOver += GameOver;
 }
Exemple #2
0
 private void Reset()
 {
     agent.EndEpisode();
     Destroy(agent.gameObject);
     agent = Instantiate(agentPrefab);
     agent.Init(board, 0);
     board.ResetPieces();
 }
Exemple #3
0
    private void NewTurn(BoardState newState)
    {
        if (gameOver)
        {
            return;
        }

        Move m = board.currentGame.GetLastMove();

        if (m.capturedPiece.HasValue)
        {
            // Reward the team that captured a piece, while punishing the team who's piece was captured
            // Queen .9
            // Rook .5
            // Bishop/Knight .3
            // Squire .2
            // Pawn .1
            // float val = 0.1f * (float)m.capturedPiece.Value.GetMaterialValue();
            float val = 0.1f;

            Hexmachina positiveAgent = m.lastTeam == Team.White ? whiteAI ? whiteAgent : null : m.lastTeam == Team.Black ? blackAI ? blackAgent : null : null;
            Hexmachina negativeAgent = m.lastTeam == Team.White ? blackAI ? blackAgent : null : m.lastTeam == Team.Black ? whiteAI ? whiteAgent : null : null;

            positiveAgent?.AddReward(val);
            negativeAgent?.AddReward(-val);
        }

        // Reward the team that checked or mated, but punish the team that was checked or mated
        // if(newState.checkmate != Team.None){ }
        // else if(newState.check != Team.None)
        // {
        //     if(newState.check == Team.White)
        //     {
        //         if(whiteAI)
        //             whiteAgent?.AddReward(-0.2f);
        //         if(blackAI)
        //             blackAgent?.AddReward(0.2f);
        //     }
        //     else
        //     {
        //         if(whiteAI)
        //             whiteAgent?.AddReward(0.2f);
        //         if(blackAI)
        //             blackAgent?.AddReward(-0.2f);
        //     }
        // }

        Hexmachina agent = newState.currentMove switch {
            Team.White when whiteAI => whiteAgent,
                   Team.Black when blackAI => blackAgent,
                   _ => null
        };

        // agent?.RequestDecision();
        nextDecision = agent;
    }
}
Exemple #4
0
    private void Start()
    {
        orgFixedTimestep    = Time.fixedDeltaTime;
        Time.fixedDeltaTime = fixedTimestep;

        board.newTurn  += NewTurn;
        board.gameOver += GameOver;

        SpawnAI();

        if (whiteAI)
        {
            nextDecision = whiteAgent;
        }
    }
Exemple #5
0
 private void SpawnAI()
 {
     if (whiteAI)
     {
         if (whiteAgent != null)
         {
             Destroy(whiteAgent.gameObject);
         }
         whiteAgent = Instantiate(agentPrefab);
         whiteAgent.Init(board, 0);
     }
     if (blackAI)
     {
         if (blackAgent != null)
         {
             Destroy(blackAgent.gameObject);
         }
         blackAgent = Instantiate(agentPrefab);
         blackAgent.Init(board, 1);
     }
 }