An Avalon (Resistance) engine for simulating, replaying, or scripting games
Right now the engine can be used to run a non-interactive game using custom deciders (bots).
AvalonGameController *c = [AvalonGameController new];
c.engine = [AvalonEngine engine];
c.engine.delegate = c;
c.bot = [JavaScriptDecider deciderWithScript:BundledScript(@"simple_bot")];
AvalonGame *g = [AvalonGame gameWithVariant:AvalonVariantDefault];
for (int i = 1; i <= 10; i++) {
AvalonPlayer *p = [AvalonPlayer playerWithId:[NSString stringWithFormat:@"BOT %d", i]];
[g addPlayer:p];
}
while (! [g isFinished]) {
[c.engine step:g];
}
BOOL goodWin = (g.passedQuestCount > g.failedQuestCount) && (g.assassinatedPlayer.role.type != AvalonRoleMerlin);
All deciders must implement the AvalonDecider protocol:
@protocol AvalonDecider <NSObject>
- (NSArray *)questProposalForGameState:(AvalonGame *)state;
- (BOOL)acceptProposalForGameState:(AvalonGame *)state;
- (BOOL)passQuestForGameState:(AvalonGame *)state;
- (NSString *)playerIdToAssassinateForGameState:(AvalonGame *)state;
@end
See the AbstractDecider class for an example implementation.
Deciders can also be implemented in javascript using a similar interface:
var proposeQuest = function(state) { /* array of player id strings */ };
var acceptProposal = function(state) { /* boolean for vote */ };
var passQuest = function(state) { /* boolean for pass */ };
var assassinatePlayer = function(state) { /* player id string to assassinate */ };
See the wiki page
Update, getting prettier:
Very crude example now included!