File: DaggerAI.m

package info (click to toggle)
gridlock.app 1.10-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,556 kB
  • sloc: objc: 10,334; ansic: 669; makefile: 12
file content (38 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (7)
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
//
//  DaggerAI.m
//  Gridlock
//
//  Created by Brian on Sun Feb 29 2004.
//  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//

#import "DaggerAI.h"
#import "DaggerGame.h"

@implementation DaggerAI

-(id)init {
  self = [super init];
  p1DaggerWeight = 20;
  p2DaggerWeight = 30;
  crownPositionWeight = 5;
  return self;
}

-(int)utilityForGame:(DaggerGame *)game player:(int)pnum {
  int daggerWeight = (pnum==1) ? p1DaggerWeight : p2DaggerWeight;
  int baserow = (pnum==1) ? 0 : [game numberOfRows]-1;
  int utility = daggerWeight*[game numberOfDaggersForPlayer:pnum];
  NSEnumerator *ce = [[game grid] enumeratorForPositionsWithValue:-pnum];
  id crownPos;
  while (crownPos=[ce nextObject]) {
    utility += crownPositionWeight * abs([crownPos row]-baserow);
  }
  return utility;
}

-(int)relativeUtilityForGame:(Game *)game player:(int)pnum {
  return [self utilityForGame:game player:pnum] - [self utilityForGame:game player:[game playerNumberMovingAfterPlayer:pnum]];
}

@end