Tree @run/7a88808b-69aa-4130-a8f5-ec42250fed0a/main (Download .tar.gz)
- debian
- Resources
- AbstractLineGame.h
- AbstractLineGame.m
- AccessorMacros.h
- AmbivalenceGame.h
- AmbivalenceGame.m
- AnyDirectionUntilBlockedMoveRule.h
- AnyDirectionUntilBlockedMoveRule.m
- AppController.h
- AppController.m
- AtaxxAI.h
- AtaxxAI.m
- AtaxxGame.h
- AtaxxGame.m
- AtaxxViewDelegate.h
- AtaxxViewDelegate.m
- AtomicAI.h
- AtomicAI.m
- AtomicGame.h
- AtomicGame.m
- AtomicViewDelegate.h
- AtomicViewDelegate.m
- AutoplayController.h
- AutoplayController.m
- BoardView.h
- BoardView.m
- BombardmentAI.h
- BombardmentAI.m
- BombardmentGame.h
- BombardmentGame.m
- BreakthroughAI.h
- BreakthroughAI.m
- CatsAndDogsAI.h
- CatsAndDogsAI.m
- CatsAndDogsGame.h
- CatsAndDogsGame.m
- CatsAndDogsViewDelegate.h
- CatsAndDogsViewDelegate.m
- CheckersAI.h
- CheckersAI.m
- CheckersGame.h
- CheckersGame.m
- CheckersViewDelegate.h
- CheckersViewDelegate.m
- ClientController.h
- ClientController.m
- CocoaAdditions.h
- CocoaAdditions.m
- ConnectFourAI.h
- ConnectFourAI.m
- ConnectFourGame.h
- ConnectFourGame.m
- DaggerAI.h
- DaggerAI.m
- DaggerGame.h
- DaggerGame.m
- DCHypergrid.h
- DCHypergrid.m
- DCHypergridPosition.h
- DCHypergridPosition.m
- DCHypergridPositionEnumerator.h
- DCHypergridPositionEnumerator.m
- DiagonalsGame.h
- DiagonalsGame.m
- DominionGame.h
- DominionGame.m
- EDCommonDefines.h
- EDIPSocket.h
- EDIPSocket.m
- EDObjcRuntime.h
- EDSocket.h
- EDSocket.m
- EDTCPSocket.h
- EDTCPSocket.m
- FiancoAI.h
- FiancoAI.m
- FiancoGame.h
- FiancoGame.m
- FissionAI.h
- FissionAI.m
- FissionGame.h
- FissionGame.m
- FiveFieldKonoAI.h
- FiveFieldKonoAI.m
- FiveFieldKonoGame.h
- FiveFieldKonoGame.m
- functions.h
- functions.m
- FusionGame.h
- FusionGame.m
- Game.h
- Game.m
- GameConfiguration.h
- GameConfiguration.m
- GameController.h
- GameController.m
- GameHistory.h
- GameHistory.m
- GenericAI.h
- GenericAI.m
- GlassBeadGame.h
- GlassBeadGame.m
- GlassBeadViewDelegate.h
- GlassBeadViewDelegate.m
- GNUmakefile
- GNUmakefile.preamble
- GomokuAI.h
- GomokuAI.m
- GomokuGame.h
- GomokuGame.m
- GravityAI.h
- GravityAI.m
- GravityGame.h
- GravityGame.m
- GravityViewDelegate.h
- GravityViewDelegate.m
- Gridlock.pcproj
- Gridlock.pcproj.backup
- GridlockGameState.h
- GridlockGameState.m
- HexapawnAI.h
- HexapawnAI.m
- HexapawnGame.h
- HexapawnGame.m
- hypergrid.c
- hypergrid.d
- hypergrid.h
- ImageStore.h
- ImageStore.m
- InfoPlist.strings
- LifeAI.h
- LifeAI.m
- LifeGame.h
- LifeGame.m
- main.d
- main.m
- MorayEelsGame.h
- MorayEelsGame.m
- MyWindow.h
- MyWindow.m
- NetConnection.h
- NetConnection.m
- NSFileHandle+Extensions.h
- NSFileHandle+Extensions.m
- NSObject+Extensions.h
- NSObject+Extensions.m
- OrthokonGame.h
- OrthokonGame.m
- osdep.h
- PC.project
- PC.project.backup
- PhotonicAttackGame.h
- PhotonicAttackGame.m
- PlayerTurnIndicatorView.h
- PlayerTurnIndicatorView.m
- Preferences.h
- Preferences.m
- PrefsWindowController.h
- PrefsWindowController.m
- QuadWrangleGame.h
- QuadWrangleGame.m
- ReactorGame.h
- ReactorGame.m
- ReactorViewDelegate.h
- ReactorViewDelegate.m
- README.GNUstep
- readme.html
- RendezvousUtils.h
- RendezvousUtils.m
- ReversiAI.h
- ReversiAI.m
- ReversiGame.h
- ReversiGame.m
- SabotageAI.h
- SabotageAI.m
- SabotageGame.h
- SabotageGame.m
- SabotageViewDelegate.h
- SabotageViewDelegate.m
- ServerController.h
- ServerController.m
- ThinkAheadAI.h
- ThinkAheadAI.m
- ThinkAheadGame.h
- ThinkAheadGame.m
- ThinkAheadViewDelegate.h
- ThinkAheadViewDelegate.m
- TongaGame.h
- TongaGame.m
- TourneyAI.h
- TourneyAI.m
- TourneyGame.h
- TourneyGame.m
- WallGameViewDelegate.h
- WallGameViewDelegate.m
- ZoneshAI.h
- ZoneshAI.m
- ZoneshGame.h
- ZoneshGame.m
- ZoneshViewDelegate.h
- ZoneshViewDelegate.m
ThinkAheadGame.m @run/7a88808b-69aa-4130-a8f5-ec42250fed0a/main — raw · history · blame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | // // ThinkAheadGame.m // Gridlock // // Created by Brian on 3/26/05. // Copyright 2005 __MyCompanyName__. All rights reserved. // #import "ThinkAheadGame.h" static int MOVE_START_VALUE = -10; static int USED_CELL_VALUE = -11; static id valueStrings[] = { @"-9", @"-7", @"-6", @"-6", @"-5", @"-5", @"-4", @"-4", @"-4", @"-3", @"-3", @"-3", @"-2", @"-2", @"-2", @"-2", @"-1", @"-1", @"-1", @"-1", @"-1", @"0", @"0", @"0", @"0", @"0", @"1", @"1", @"1", @"1", @"1", @"2", @"2", @"2", @"2", @"2", @"2", @"3", @"3", @"3", @"3", @"3", @"4", @"4", @"4", @"4", @"5", @"5", @"5", @"5", @"6", @"6", @"6", @"7", @"7", @"7", @"8", @"8", @"9", @"9", @"10", @"15", @"-10", @"0"}; // -10 is starting position, last one should eventually be "mystery box" static NSArray *gGridValues=nil; static NSArray *gridValues() { if (!gGridValues) { gGridValues = [[NSArray alloc] initWithObjects:valueStrings count:64]; } return gGridValues; } @implementation ThinkAheadGame -(void)reset { [super reset]; [self setGrid:[DCHypergrid gridWithRows:8 columns:8]]; NSArray *randomValues = [gridValues() arrayWithObjectsInRandomOrder_]; NSEnumerator *pe = [[self grid] positionEnumerator]; id pos; int index=0; while(pos=[pe nextObject]) { [self setValue:[[randomValues objectAtIndex:index++] intValue] atPosition:pos]; } p1Score = p2Score = 0; } -(NSArray *)allValidMoveSequences { id startpos = [[self grid] positionWithValue:MOVE_START_VALUE]; if (!startpos) return nil; NSMutableArray *moves = [NSMutableArray array]; // player 1 moves horizontally, 2 moves vertically if ([self currentPlayerNumber]==1) { int r = [startpos row]; int c; for(c=0; c<[self numberOfColumns]; c++) { if ([self valueAtRow:r column:c]>MOVE_START_VALUE) { [moves addObject:[[DCHypergridPosition positionWithRow:r column:c] arrayWithSelf_]]; } } } else { int c = [startpos column]; int r; for(r=0; r<[self numberOfRows]; r++) { if ([self valueAtRow:r column:c]>MOVE_START_VALUE) { [moves addObject:[[DCHypergridPosition positionWithRow:r column:c] arrayWithSelf_]]; } } } return moves; } -(BOOL)prepareMoveSequence:(NSArray *)positions { if ([positions count]!=1) return NO; id movepos = [positions lastObject]; id startpos = [[self grid] positionWithValue:MOVE_START_VALUE]; [self resetFutureGrid]; [[self futureGrid] setValue:USED_CELL_VALUE atPosition:startpos]; [[self futureGrid] setValue:MOVE_START_VALUE atPosition:movepos]; return YES; } -(void)updateFromPreparedMove { id movepos = [[self futureGrid] positionWithValue:MOVE_START_VALUE]; if (movepos) { int value = [self valueAtPosition:movepos]; if ([self currentPlayerNumber]==1) p1Score+=value; else p2Score+=value; } [super updateFromPreparedMove]; } -(BOOL)isGameOver { return [[self allValidMoveSequences] count]==0; } -(BOOL)showScores { return YES; } -(int)scoreForPlayer:(int)pnum { return (pnum==1) ? p1Score : p2Score; } // these methods deal with the score ivars (since they can't be derived from the state of the board) -(Game *)copy { ThinkAheadGame *newGame = (ThinkAheadGame *)[super copy]; newGame->p1Score = p1Score; newGame->p2Score = p2Score; return newGame; } -(void)copyValuesToGame:(ThinkAheadGame *)newGame { [super copyValuesToGame:newGame]; newGame->p1Score = p1Score; newGame->p2Score = p2Score; } -(id)propertyList { id plist = [super propertyList]; // assume mutable? [plist setObject:[[NSNumber numberWithInt:p1Score] stringValue] forKey:@"p1Score"]; [plist setObject:[[NSNumber numberWithInt:p2Score] stringValue] forKey:@"p2Score"]; return plist; } -(void)updateFromPropertyList:(id)plist { [super updateFromPropertyList:plist]; p1Score = [[plist objectForKey:@"p1Score"] intValue]; p2Score = [[plist objectForKey:@"p2Score"] intValue]; } @end |