Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored game interaction using player classes
- Loading branch information
Showing
15 changed files
with
224 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// UIPlayer.h | ||
// gomoku | ||
// | ||
// Created by Konstantin Gredeskoul on 5/3/10. | ||
// Copyright 2010 Konstantin Gredeskoul, shared under MIT license. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "Player.h" | ||
#import "Game.h" | ||
#import "Move.h" | ||
|
||
@interface AIPlayer : NSObject <Player> { | ||
Game *game; | ||
} | ||
|
||
-(AIPlayer *)initWithGame:(Game *)thisGame; | ||
|
||
@property(nonatomic, strong) Game *game; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// UIPlayer.m | ||
// gomoku | ||
// | ||
// Created by Konstantin Gredeskoul on 5/3/10. | ||
// Copyright 2010 Konstantin Gredeskoul, shared under MIT license. All rights reserved. | ||
// | ||
|
||
#import "AIPlayer.h" | ||
#import "AlphaBetaPruner.h" | ||
#import "MyBest.h" | ||
|
||
@implementation AIPlayer | ||
|
||
@synthesize game; | ||
|
||
-(AIPlayer *)initWithGame:(Game *) thisGame { | ||
if (self = [super init]) { | ||
self.game = thisGame; | ||
} | ||
return self; | ||
} | ||
|
||
- (void) beginTurn { | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
AlphaBetaPruner *ai = [[AlphaBetaPruner alloc] initWithBoard:self.game.board]; | ||
MyBest *myBest = [ai chooseMove]; | ||
if (myBest != nil) { | ||
NSLog(@"AI made move [%@]", myBest); | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
[[self game] makeMove: myBest.move]; | ||
}); | ||
} else { | ||
NSLog(@"AI failed and returned a nil move"); | ||
} | ||
}); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
#import "HumanPlayer.h" | ||
|
||
@implementation HumanPlayer | ||
|
||
@synthesize game; | ||
|
||
-(HumanPlayer *)initWithGame:(Game *) thisGame { | ||
if (self = [super init]) { | ||
self.game = thisGame; | ||
} | ||
return self; | ||
} | ||
|
||
- (void) beginTurn { | ||
} | ||
|
||
|
||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.