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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0180757d7d76b94a4b58bfc145f77ae2429e52c2
4
- data.tar.gz: cb154e39260c4169fa6512fd6afaf75a6c8c3b0f
3
+ metadata.gz: 2c9bad45490fc64cbffaee6614650fcb4c95ed96
4
+ data.tar.gz: 4d479d0e2e687f21239a9d2549af3be166882f5e
5
5
  SHA512:
6
- metadata.gz: 6fa4d611faaf58df31f2acc916d6afd2e3c40af8ba0ba0a33662501bb30c091a82dd53d21e6477c72d7920184906cb0591451b3d18d707bc3b5ed639a805dbc3
7
- data.tar.gz: 75711418630a2c94d0efdfac6c2f03e52f19e95e29a046a690db803a0c56150d60deec6bc149a6c77e0e23dc458916473f5a82c51bed0775c7b86af03aff2df3
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 MovesController < ApplicationController
25
- def make
26
- game = if params[:game_id]
27
- Game.new
28
- else
29
- Game.find(params[:game_id])
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: TicTacToeMchliakh.move(params[:square], game.board)
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
- forks.sample || sticky_situation || @board.squares.empty.max_by(&:line_count)
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 forks
23
+ def fork_squares
24
24
  @board.lines.squares_that_can_fork(@number).empty
25
25
  end
26
26
 
27
- def opponent_forks
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
@@ -1,3 +1,3 @@
1
1
  module TicTacToeMchliakh
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tic_tac_toe_mchliakh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Chliakhovski