tic_tac_toe_mchliakh 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -7
- data/lib/tic_tac_toe_mchliakh/players/computer.rb +7 -7
- data/lib/tic_tac_toe_mchliakh/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2c9bad45490fc64cbffaee6614650fcb4c95ed96
|
|
4
|
+
data.tar.gz: 4d479d0e2e687f21239a9d2549af3be166882f5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba75837c2e15829ff111195acb10e4436c8fc7e9db2f1e476007540789ca024f71be17f27a5314a0e73ed007a3bb8f1b6d1310bf8aa82a2391bff4c991b4cee2
|
|
7
|
+
data.tar.gz: 8477aeac27e9b641d06855ca45222702a0bfbf651df7b7e14b76327cac0e5aeda998042a461dbb32d0e4b4a2d55adb3ec0ca56a0a28113aef422968191a9d5a2
|
data/README.md
CHANGED
|
@@ -21,15 +21,21 @@ Or install it yourself as:
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
|
-
class
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
class GamesController < ApplicationController
|
|
25
|
+
def new
|
|
26
|
+
render json: Game.create.id
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def move
|
|
30
|
+
game = Game.find(params[:id])
|
|
31
|
+
|
|
32
|
+
result = TicTacToeMchliakh.move(square, game.board)
|
|
33
|
+
|
|
34
|
+
if result[:board]
|
|
35
|
+
game.update_attributes(board: result[:board])
|
|
30
36
|
end
|
|
31
37
|
|
|
32
|
-
render json:
|
|
38
|
+
render json: result
|
|
33
39
|
end
|
|
34
40
|
end
|
|
35
41
|
```
|
|
@@ -6,7 +6,7 @@ module TicTacToeMchliakh
|
|
|
6
6
|
if line
|
|
7
7
|
line.squares.empty.sample
|
|
8
8
|
else
|
|
9
|
-
|
|
9
|
+
fork_squares.sample || fork_safe_square || @board.squares.empty.max_by(&:line_count)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -20,15 +20,11 @@ module TicTacToeMchliakh
|
|
|
20
20
|
@board.lines.can_lose(@number).sample
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def
|
|
23
|
+
def fork_squares
|
|
24
24
|
@board.lines.squares_that_can_fork(@number).empty
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def
|
|
28
|
-
@board.lines.squares_that_can_be_forked(@number).empty
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def sticky_situation
|
|
27
|
+
def fork_safe_square
|
|
32
28
|
_opponent_forks = opponent_forks
|
|
33
29
|
|
|
34
30
|
if opponent_forks.size > 1
|
|
@@ -40,5 +36,9 @@ module TicTacToeMchliakh
|
|
|
40
36
|
opponent_forks.first
|
|
41
37
|
end
|
|
42
38
|
end
|
|
39
|
+
|
|
40
|
+
def opponent_forks
|
|
41
|
+
@board.lines.squares_that_can_be_forked(@number).empty
|
|
42
|
+
end
|
|
43
43
|
end
|
|
44
44
|
end
|