private void NewTurn(BoardState newState) { if (newState.currentMove == Team.Black) { Move move = board.currentGame.GetLastMove(); if (move.capturedPiece.HasValue) { agent.AddReward(0.1f); } if (newState.checkmate != Team.Black) { Debug.Log("Failed"); agent.AddReward(-1); Reset(); } else { Debug.Log("Success"); agent.AddReward(1); } } else if (newState.currentMove == Team.White) { agent.RequestDecision(); } }
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; } }
private void NewTurn(BoardState newState) { if (newState.currentMove == Team.Black) { if (newState.checkmate != Team.Black) { Debug.Log("Failed"); agent.AddReward(-1); Reset(); } else { Debug.Log("Success"); agent.AddReward(1); } } else if (newState.currentMove == Team.White) { agent.RequestDecision(); } }
public void GameOver(Game game) { switch (game.winner) { case Winner.White: if (whiteAI) { whiteAgent?.AddReward(1); } if (blackAI) { blackAgent?.AddReward(-1); } break; case Winner.Black: if (whiteAI) { whiteAgent?.AddReward(-1); } if (blackAI) { blackAgent?.AddReward(1); } break; case Winner.Draw: if (whiteAI) { whiteAgent?.AddReward(0); } if (blackAI) { blackAgent?.AddReward(0); } break; case Winner.None: if (whiteAI) { whiteAgent?.AddReward(0); } if (blackAI) { blackAgent?.AddReward(0); } break; } if (whiteAI && whiteAgent != null) { whiteAgent.EndEpisode(); Destroy(whiteAgent.gameObject); } if (blackAI && blackAgent != null) { blackAgent.EndEpisode(); Destroy(blackAgent.gameObject); } gameOver = true; // Reset(); }