Game class now tracks board state and moves, as strings, and can step through its history.
Fixed another bug in Go (you could drag your captured stones back to the board!)
1 /* This code is based on Apple's "GeekGameBoard" sample code, version 1.0.
2 http://developer.apple.com/samplecode/GeekGameBoard/
3 Copyright © 2007 Apple Inc. Copyright © 2008 Jens Alfke. All Rights Reserved.
5 Redistribution and use in source and binary forms, with or without modification, are permitted
6 provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this list of
11 conditions and the following disclaimer in the documentation and/or other materials provided
12 with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
17 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
21 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #import "QuartzUtils.h"
31 - (id) copyWithZone: (NSZone*)zone
33 Bit *clone = [super copyWithZone: zone];
34 clone->_owner = _owner;
44 @synthesize owner=_owner;
46 - (BOOL) isFriendly {return _owner.friendly;}
47 - (BOOL) isUnfriendly {return _owner.unfriendly;}
50 - (NSString*) identifier
54 // Defaults to just identifying the owner:
55 return [NSString stringWithFormat: @"p%i", _owner.index+1];
61 NSNumber *scale = [self valueForKeyPath: @"transform.scale"];
62 return scale.floatValue;
65 - (void) setScale: (CGFloat)scale
67 [self setValue: [NSNumber numberWithFloat: scale]
68 forKeyPath: @"transform.scale"];
74 NSNumber *rot = [self valueForKeyPath: @"transform.rotation"];
75 return round( rot.doubleValue * 180.0 / M_PI );
78 - (void) setRotation: (int)rotation
80 [self setValue: [NSNumber numberWithDouble: rotation*M_PI/180.0]
81 forKeyPath: @"transform.rotation"];
87 return self.zPosition >= kPickedUpZ;
90 - (void) setPickedUp: (BOOL)up
92 if( up != self.pickedUp ) {
93 CGFloat shadow, offset, radius, opacity, z, scale;
101 _restingZ = self.zPosition;
103 shadow = offset = radius = 0.0;
111 self.shadowOpacity = shadow;
112 self.shadowOffset = CGSizeMake(offset,-offset);
113 self.shadowRadius = radius;
115 self.opacity = opacity;
121 - (BOOL)containsPoint:(CGPoint)p
123 // Make picked-up pieces invisible to hit-testing.
124 // Otherwise, while dragging a Bit, hit-testing the cursor position would always return
125 // that Bit, since it's directly under the cursor...
129 return [super containsPoint: p];
133 -(id<BitHolder>) holder
135 // Look for my nearest ancestor that's a BitHolder:
136 for( CALayer *layer=self.superlayer; layer; layer=layer.superlayer ) {
137 if( [layer conformsToProtocol: @protocol(BitHolder)] )
138 return (id<BitHolder>)layer;
139 else if( [layer isKindOfClass: [Bit class]] )
148 // "Pop" the Bit by expanding it 5x as it fades away:
151 // Removing the view from its superlayer right now would cancel the animations.
152 // Instead, defer the removal until sometime shortly after the animations finish:
153 [self performSelector: @selector(removeFromSuperlayer) withObject: nil afterDelay: 1.0];