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 +1 -2
- data/lib/linotype/move.rb +3 -0
- data/lib/linotype/simulator.rb +2 -1
- data/lib/linotype/strategy.rb +15 -2
- data/lib/linotype/version.rb +1 -1
- metadata +1 -1
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
|
-
|
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?
|
data/lib/linotype/simulator.rb
CHANGED
data/lib/linotype/strategy.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
module Linotype
|
2
2
|
class Strategy
|
3
3
|
|
4
|
-
|
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
|
data/lib/linotype/version.rb
CHANGED