linotype 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/linotype/game.rb CHANGED
@@ -173,8 +173,7 @@ module Linotype
173
173
  def uncovered_tiles
174
174
  all_tiles.select { |tile| !tile.covered_by }
175
175
  end
176
- private :uncovered_tiles
177
-
176
+
178
177
  def defended_tiles(player)
179
178
  tile_rows.flatten.select { |tile| player && tile.covered_by == player && tile.defended? }
180
179
  end
data/lib/linotype/move.rb CHANGED
@@ -44,6 +44,8 @@ module Linotype
44
44
  self.score["covered_#{time}".to_sym] = @game.covered_tiles(player).count
45
45
  self.score["edges_#{time}".to_sym] = @game.edge_tiles(player).count
46
46
  self.score["corners_#{time}".to_sym] = @game.corner_tiles(player).count
47
+ self.score["corners_defended_#{time}".to_sym] = (@game.defended_tiles(player) & @game.corner_tiles(player)).count
48
+ self.score["remaining_uncovered_#{time}".to_sym] = @game.uncovered_tiles.count
47
49
  end
48
50
 
49
51
  def calculate_net_scores
@@ -51,6 +53,7 @@ module Linotype
51
53
  self.score[:covered] = score[:covered_after] - score[:covered_before]
52
54
  self.score[:edges] = score[:edges_after] - score[:edges_before]
53
55
  self.score[:corners] = score[:corners_after] - score[:corners_before]
56
+ self.score[:corners_defended] = score[:corners_defended_after] - score[:corners_defended_before]
54
57
  end
55
58
 
56
59
  def valid?
@@ -21,8 +21,9 @@ module Linotype
21
21
  end
22
22
  game.print_board
23
23
  game.print_scores
24
+ puts "---------------"
24
25
  end
25
- game
26
+ puts "Game Over!"
26
27
  end
27
28
 
28
29
  end
@@ -1,8 +1,17 @@
1
1
  module Linotype
2
2
  class Strategy
3
3
 
4
- LETTERPRESS_FAN_HEURISTIC = ->(move) do
5
- move.score[:covered] + move.score[:defended] + move.score[:edges] + move.score[:corners]
4
+ EDGE_AND_CORNER = ->(move) do
5
+ score = move.score[:covered] + move.score[:defended] + move.score[:edges] + move.score[:corners]
6
+ score += 100000 if move.score[:remaining_uncovered_after] == 0
7
+ score
8
+ end
9
+
10
+ CORNER_LOVER = ->(move) do
11
+ score = move.score[:covered] + move.score[:defended] + move.score[:edges] + move.score[:corners]
12
+ score += 10 if (move.score[:corners_defended_before] == 0 && move.score[:corners_defended_after] > 0)
13
+ score += 100000 if move.score[:remaining_uncovered_after] == 0
14
+ score
6
15
  end
7
16
 
8
17
  MAX_SIX_LETTERS = ->(move) do
@@ -27,5 +36,9 @@ module Linotype
27
36
  scoring_algorithm.call move
28
37
  end
29
38
 
39
+ def self.predefined(strategy_name)
40
+ new(const_get(strategy_name))
41
+ end
42
+
30
43
  end
31
44
  end
@@ -1,3 +1,3 @@
1
1
  module Linotype
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linotype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: