Auto-starting a Table/Match
Moderators: North, BetaSteward, noxx, jeffwadsworth, JayDi, TheElk801, LevelX, CCGHQ Admins
Auto-starting a Table/Match
by ShivaFang » 20 Jul 2016, 02:28
I'm having trouble getting the code to auto-start a Table and Match. The goal here is to start a match with computer AIs as soon as a match ends. This is for a genetic algorithm designed to modify decks to find decks that win most often. I already have it set up so that the the AIs use random decks (which will be changed to decks that win most often)
In the endGame code I have something like this - which isn't working for me;
In the endGame code I have something like this - which isn't working for me;
- Code: Select all
if (checkIfMatchEnds){
// create a new match
MatchOptions edt = this.getOptions();
try {
EvolvingDuelMatch m = new EvolvingDuelMatch(edt);
/*for (OmniDeck deck:setDecks.values()){
m.addPlayer(new MonteCarloPlayer2("comp", RangeOfInfluence.ALL, 10), deck);
}*/
List<String> playerTypes = new ArrayList<String>();
playerTypes.add("Computer - montecarlo");
playerTypes.add("Computer - montecarlo");
DeckValidator dv = DeckValidatorFactory.getInstance().createDeckValidator(this.getOptions().getGameType());
Table T = new Table(UUID.randomUUID(),this.getOptions().getGameType(),"Evolving Duel","",dv, playerTypes,
TableRecorderImpl.getInstance(), m);
T.initGame();
} catch (GameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Re: Auto-starting a Table/Match
by ShivaFang » 20 Jul 2016, 13:57
I figured maybe I need a room and a tablemanager, so I tried this. Still no joy.
BTW EvolvingDuelMatch is a variation of the TwoPlayerMatch but with all the code I need to select random decks and evolve them when the match is over. It's the class that I'm doing this in, too.
BTW EvolvingDuelMatch is a variation of the TwoPlayerMatch but with all the code I need to select random decks and evolve them when the match is over. It's the class that I'm doing this in, too.
- Code: Select all
EvolvingDuelMatch m = new EvolvingDuelMatch(edt);
List<String> playerTypes = new ArrayList<String>();
playerTypes.add("Computer - montecarlo");
playerTypes.add("Computer - montecarlo");
DeckValidator dv = DeckValidatorFactory.getInstance().createDeckValidator(this.getOptions().getGameType());
EvolvingRoom R = new EvolvingRoom();
this.getOptions().getPlayerTypes().clear();
this.getOptions().getPlayerTypes().add("Computer - montecarlo");
this.getOptions().getPlayerTypes().add("Computer - montecarlo");
UUID own = playerOwner;
TableView tv = R.createTable(this.getOptions());
Player pl;
/*
for (OmniDeck deck:setDecks.values()){
pl = new MonteCarloPlayer2("random",RangeOfInfluence.ALL,10);
TableManager.getInstance().addPlayer(pl.getId(), tableId, pl, "Computer - montecarlo", deck);
}*/
TableManager.getInstance().startMatch(own, R.getRoomId(), tv.getTableId());
Re: Auto-starting a Table/Match
by ShivaFang » 21 Jul 2016, 14:01
OKay, well, I got it to work. It's super janky but it's functional. I can't observe the games (other than what I print to console) but it gets the job done.
If anyone else needs this for any reason I'll stick the code here. I had to create my own room extnding GameRoomImpl. You'll probably also need your own match to call it and remove the tables and matches from the GameManager.
If anyone else needs this for any reason I'll stick the code here. I had to create my own room extnding GameRoomImpl. You'll probably also need your own match to call it and remove the tables and matches from the GameManager.
- Code: Select all
public TableView createTable(MatchOptions options, Deck deck) throws MageException
{
Table table = TableManager.getInstance().createTable(getRoomId(), null, options);
Seat[] seats = table.getSeats();
UUID tableId = table.getId();
for (int n =0; n<seats.length; n++){
seats[n].setPlayer(new MonteCarloPlayer2("random", RangeOfInfluence.ALL, 10));
}
this.tables.put(table.getId(), table);
TableController tc = TableManager.getInstance().getController(tableId);
Player pl;
table.setState(TableState.STARTING);
startGame(tc, deck);
return new TableView(table);
}
private void startGame(TableController tc, Deck deck) throws MageException{
UUID choosingPlayerId = null;
Match match = tc.getMatch();
Table table = tc.getTable();
if (match instanceof EvolvingDuelMatch) ((EvolvingDuelMatch)match).table = table;
ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<UUID, UUID>();
for (Seat s : table.getSeats()){
//tc.joinTable(s.getPlayer().getId(), deck.getName(), "Computer - montecarlo", 10, deck.getDeckCardLists(), "");
userPlayerMap.put(s.getPlayer().getId(), s.getPlayer().getId());
match.addPlayer(s.getPlayer(), deck);
}
table.initGame();
match.startGame();
GameOptions gameOptions = new GameOptions();
gameOptions.rollbackTurnsAllowed = match.getOptions().isRollbackTurnsAllowed();
match.getGame().setGameOptions(gameOptions);
try {
GameManager.getInstance().createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
}
catch (Exception ex)
{
//logger.fatal("Error starting game table: " + this.table.getId(), ex);
if (table != null) {
TableManager.getInstance().removeTable(table.getId());
}
if (match != null)
{
Game game = match.getGame();
if (game != null) {
GameManager.getInstance().removeGame(game.getId());
}
}
}
}
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 6 guests