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
DiagonalsGame.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 | // // DiagonalsGame.m // Gridlock // // Created by Brian on Sat Jul 10 2004. // Copyright (c) 2004 __MyCompanyName__. All rights reserved. // #import "DiagonalsGame.h" @implementation DiagonalsGame idAccessor(preparedMove, setPreparedMove) -(void)reset { [super reset]; [self setGrid:[DCHypergrid gridWithRows:[[[self configurationInfo] objectForKey:@"rows"] intValue] columns:[[[self configurationInfo] objectForKey:@"cols"] intValue]]]; p1Score = p2Score = 0; [self setPreparedMove:nil]; } -(BOOL)prepareMoveSequence:(NSArray *)positions { [self setPreparedMove:[positions lastObject]]; return YES; } -(NSArray *)positionsOfAllChangingCells { return [[self preparedMove] arrayWithSelf_]; } -(int)futureValueAtPosition:(DCHypergridPosition *)pos { if ([pos isEqual:[self preparedMove]]) return [self currentPlayerNumber]; else return [self valueAtPosition:pos]; } -(int)scoreForDiagonalFromPosition:(id)pos northEast:(BOOL)ne { int score = 1; // count position moved to BOOL longerThan1 = NO; // corners don't count int pnum = [self valueAtPosition:pos]; // go forward diagonally until we hit the edge or an empty cell int r = [pos row]; int c = [pos column]; int dc = ne ? 1 : -1; while ([self isValidRow:r+1 column:c+dc]) { int val = [self valueAtRow:r+1 column:c+dc]; if (val==0) return 0; // not a full diagonal if (val==pnum) score++; longerThan1 = YES; r++; c+=dc; } // repeat in opposite direction r = [pos row]; c = [pos column]; while ([self isValidRow:r-1 column:c-dc]) { int val = [self valueAtRow:r-1 column:c-dc]; if (val==0) return 0; // not a full diagonal if (val==pnum) score++; longerThan1 = YES; r--; c-=dc; } return (longerThan1) ? score : 0; } -(int)scoreForDiagonalsFromPosition:(id)pos { return [self scoreForDiagonalFromPosition:pos northEast:YES] + [self scoreForDiagonalFromPosition:pos northEast:NO]; } -(void)updateFromPreparedMove { id pos = [self preparedMove]; [super updateFromPreparedMove]; // check for completed diagonals int score = [self scoreForDiagonalsFromPosition:pos]; if ([self currentPlayerNumber]==1) { p1Score += score; } else { p2Score += score; } } -(NSArray *)allValidMoveSequences { return [[[self grid] allPositionsWithValue:0] valuesByObjectsPerformingSelector:@selector(arrayWithSelf_)]; } -(BOOL)showScores { return YES; } -(int)scoreForPlayer:(int)pnum { return (pnum==1) ? p1Score : p2Score; } -(BOOL)isGameOver { return !([[self grid] hasCellWithValue:0]); } // these methods deal with the score ivars (since they can't be derived from the state of the board) -(Game *)copy { DiagonalsGame *newGame = (DiagonalsGame *)[super copy]; newGame->p1Score = p1Score; newGame->p2Score = p2Score; return newGame; } -(void)copyValuesToGame:(DiagonalsGame *)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 |