# HG changeset patch # User Jens Alfke # Date 1216686741 25200 # Node ID 2eb229411d73787d875310d47de07f03d4edb0cb # Parent 7c9ecb09a61288b84c72dd9f430d9e7e382d8f30 * Added API to Stack for removing bits. * GoGame correctly saves/restores number of captured pieces. * Improved positioning of captured-piece Stacks in GoGame. * New Go piece icons. * Added "Warn" function to GGBUtils. diff -r 7c9ecb09a612 -r 2eb229411d73 Resources/Stone-black.png Binary file Resources/Stone-black.png has changed diff -r 7c9ecb09a612 -r 2eb229411d73 Resources/Stone-black.psd Binary file Resources/Stone-black.psd has changed diff -r 7c9ecb09a612 -r 2eb229411d73 Resources/Stone-white.png Binary file Resources/Stone-white.png has changed diff -r 7c9ecb09a612 -r 2eb229411d73 Resources/Stone-white.psd Binary file Resources/Stone-white.psd has changed diff -r 7c9ecb09a612 -r 2eb229411d73 Source/GGBUtils.h --- a/Source/GGBUtils.h Fri Jul 18 13:26:59 2008 -0700 +++ b/Source/GGBUtils.h Mon Jul 21 17:32:21 2008 -0700 @@ -20,6 +20,11 @@ */ +#ifndef Warn +#define Warn(MSG,...) NSLog(@"WARNING: " #MSG,__VA_ARGS__) +#endif + + /** Handy utility for assigning a new value to a retained instance variable. Use as: setObj(&_instanceVar, newValue); It releases the old value and retains the new one. */ diff -r 7c9ecb09a612 -r 2eb229411d73 Source/GGBUtils.m --- a/Source/GGBUtils.m Fri Jul 18 13:26:59 2008 -0700 +++ b/Source/GGBUtils.m Mon Jul 21 17:32:21 2008 -0700 @@ -72,12 +72,12 @@ if( path ) url = [NSURL fileURLWithPath: path]; else { - NSLog(@"WARNING: Couldn't find sound %@",name); + Warn(@"Couldn't find sound %@",name); return 0; } SystemSoundID soundID; if( AudioServicesCreateSystemSoundID((CFURLRef)url,&soundID) != noErr ) { - NSLog(@"WARNING: Couldn't load sound %@",url); + Warn(@"Couldn't load sound %@",url); return 0; } diff -r 7c9ecb09a612 -r 2eb229411d73 Source/Game.m --- a/Source/Game.m Fri Jul 18 13:26:59 2008 -0700 +++ b/Source/Game.m Mon Jul 21 17:32:21 2008 -0700 @@ -325,7 +325,7 @@ @try{ if( ! [self applyMoveString: move] ) { _currentTurnNo = oldTurnNo; - NSLog(@"WARNING: %@ failed to apply stored move '%@'!", self,move); + Warn(@"%@ failed to apply stored move '%@'!", self,move); return; } }@finally{ @@ -340,7 +340,7 @@ } if( ! [self.stateString isEqual: state] ) { _currentTurnNo = oldTurnNo; - NSLog(@"WARNING: %@ failed to apply stored state '%@'!", self,state); + Warn(@"%@ failed to apply stored state '%@'!", self,state); return; } } else diff -r 7c9ecb09a612 -r 2eb229411d73 Source/GoGame.m --- a/Source/GoGame.m Fri Jul 18 13:26:59 2008 -0700 +++ b/Source/GoGame.m Mon Jul 21 17:32:21 2008 -0700 @@ -39,7 +39,7 @@ self = [super init]; if (self != nil) { [self setNumberOfPlayers: 2]; - [(Player*)[_players objectAtIndex: 0] setName: @"Red"]; + [(Player*)[_players objectAtIndex: 0] setName: @"Black"]; [(Player*)[_players objectAtIndex: 1] setName: @"White"]; } return self; @@ -48,8 +48,9 @@ - (void) setUpBoard { int dimensions = [[self class] dimensions]; - CGSize size = _table.bounds.size; - CGFloat boardSide = MIN(size.width,size.height); + CGRect tableBounds = _table.bounds; + CGSize size = tableBounds.size; + CGFloat boardSide = MIN(size.width* dimensions/(CGFloat)(dimensions+2),size.height); RectGrid *board = [[RectGrid alloc] initWithRows: dimensions columns: dimensions frame: CGRectMake(floor((size.width-boardSide)/2), floor((size.height-boardSide)/2), @@ -73,25 +74,29 @@ CGRect gridFrame = board.frame; CGFloat pieceSize = (int)board.spacing.width & ~1; // make sure it's even - CGFloat captureHeight = gridFrame.size.height-4*pieceSize; - _captured[0] = [[Stack alloc] initWithStartPos: CGPointMake(2*pieceSize,0) + CGFloat captureMinY = CGRectGetMinY(tableBounds) + pieceSize/2, + captureHeight = size.height - pieceSize; + _captured[0] = [[Stack alloc] initWithStartPos: CGPointMake(pieceSize/2,0) spacing: CGSizeMake(0,pieceSize) wrapInterval: floor(captureHeight/pieceSize) - wrapSpacing: CGSizeMake(-pieceSize,0)]; - _captured[0].frame = CGRectMake(CGRectGetMinX(gridFrame)-3*pieceSize, - CGRectGetMinY(gridFrame)+3*pieceSize, - 2*pieceSize, captureHeight); + wrapSpacing: CGSizeMake(pieceSize,0)]; + _captured[0].frame = CGRectMake(CGRectGetMinX(tableBounds), + captureMinY, + CGRectGetMinX(gridFrame)-CGRectGetMinX(tableBounds), + captureHeight); _captured[0].zPosition = kPieceZ+1; [_table addSublayer: _captured[0]]; [_captured[0] release]; - _captured[1] = [[Stack alloc] initWithStartPos: CGPointMake(0,captureHeight) + _captured[1] = [[Stack alloc] initWithStartPos: CGPointMake(pieceSize/2,captureHeight) spacing: CGSizeMake(0,-pieceSize) wrapInterval: floor(captureHeight/pieceSize) - wrapSpacing: CGSizeMake(pieceSize,0)]; - _captured[1].frame = CGRectMake(CGRectGetMaxX(gridFrame)+pieceSize, - CGRectGetMinY(gridFrame)+pieceSize, - 2*pieceSize, captureHeight); + wrapSpacing: CGSizeMake(-pieceSize,0)]; + _captured[1].frame = CGRectMake(CGRectGetMaxX(gridFrame), + captureMinY, + CGRectGetMaxX(tableBounds)-CGRectGetMaxX(gridFrame), + captureHeight); + _captured[1].startPos = CGPointMake(CGRectGetMaxX(_captured[1].bounds)-pieceSize/2, captureHeight); _captured[1].zPosition = kPieceZ+1; [_table addSublayer: _captured[1]]; [_captured[1] release]; @@ -101,13 +106,13 @@ - (CGImageRef) iconForPlayer: (int)playerNum { - return GetCGImageNamed( playerNum ?@"bot086.png" :@"bot089.png" ); + return GetCGImageNamed( playerNum ?@"Stone-white.png" :@"Stone-black.png" ); } - (Piece*) pieceForPlayer: (int)index { - NSString *imageName = index ?@"bot086.png" :@"bot089.png"; - CGFloat pieceSize = (int)(_board.spacing.width * 0.9) & ~1; // make sure it's even + NSString *imageName = index ?@"Stone-white.png" :@"Stone-black.png"; + CGFloat pieceSize = (int)(_board.spacing.width * 1.8) & ~1; // make sure it's even Piece *stone = [[Piece alloc] initWithImageNamed: imageName scale: pieceSize]; stone.owner = [self.players objectAtIndex: index]; return [stone autorelease]; @@ -203,12 +208,19 @@ ch = '1' + bit.owner.index; state[y*n+x] = ch; } - return [NSString stringWithCharacters: state length: n*n]; + NSMutableString *stateString = [NSMutableString stringWithCharacters: state length: n*n]; + + NSUInteger cap0=_captured[0].numberOfBits, cap1=_captured[1].numberOfBits; + if( cap0 || cap1 ) + [stateString appendFormat: @",%i,%i", cap0,cap1]; + return stateString; } - (void) setStateString: (NSString*)state { - NSLog(@"Go: setStateString: '%@'",state); + //NSLog(@"Go: setStateString: '%@'",state); + NSArray *components = [state componentsSeparatedByString: @","]; + state = [components objectAtIndex: 0]; int n = _board.rows; for( int y=0; y n ) + [self removeBit: self.topBit]; +} + - (Bit*) topBit { return [_bits lastObject]; @@ -98,6 +110,16 @@ } +- (void) removeBit: (Bit*)bit +{ + NSUInteger index = [_bits indexOfObjectIdenticalTo: bit]; + if( index != NSNotFound ) { + [bit removeFromSuperlayer]; + [_bits removeObjectAtIndex: index]; + } +} + + - (void) setHighlighted: (BOOL)highlighted { [super setHighlighted: highlighted];