matts_tictactoe_core 0.1.0 → 0.2.0
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/Gemfile.lock +1 -1
- data/lib/matts_tictactoe_core/board.rb +11 -8
- data/lib/matts_tictactoe_core/game.rb +10 -2
- data/lib/matts_tictactoe_core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba143b33d21600006aa31970563bc8cb38ec200e
|
|
4
|
+
data.tar.gz: 43753236d8c0e5d4e953b93465e9f171cc6638c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e9ede84d84dfcf7984583c9f96c9c989268155af12772b1486a945f0c221bddb5fba7b28a6813020bb229364a9f8f1e3e8003c777de5f5106746f76127ae9236
|
|
7
|
+
data.tar.gz: f564afe9f6f3048ffdd1da8f023e379faf647caac08743d9e1927dac8dbbefede1da8cdb4e28ce1499658b8c4e2943bb33d8193cd591b5c887c63c78fee91520
|
data/Gemfile.lock
CHANGED
|
@@ -3,10 +3,15 @@ require "matts_tictactoe_core/lines"
|
|
|
3
3
|
module MattsTictactoeCore
|
|
4
4
|
class Board
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
def self.ofSize(size)
|
|
7
|
+
Board.new([], size: size)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
attr_reader :moves, :size
|
|
7
11
|
|
|
8
|
-
def initialize(moves = [])
|
|
12
|
+
def initialize(moves = [], size: 3)
|
|
9
13
|
@moves = moves
|
|
14
|
+
@size = size;
|
|
10
15
|
@lines = Lines.new(self)
|
|
11
16
|
end
|
|
12
17
|
|
|
@@ -18,12 +23,8 @@ module MattsTictactoeCore
|
|
|
18
23
|
size ** 2
|
|
19
24
|
end
|
|
20
25
|
|
|
21
|
-
def size
|
|
22
|
-
3
|
|
23
|
-
end
|
|
24
|
-
|
|
25
26
|
def move(square)
|
|
26
|
-
valid_move?(square) ? Board.new(moves + [square]) : self
|
|
27
|
+
valid_move?(square) ? Board.new(moves + [square], size: size) : self
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
def valid_move?(square)
|
|
@@ -53,7 +54,9 @@ module MattsTictactoeCore
|
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
def ==(other)
|
|
56
|
-
other.class == self.class &&
|
|
57
|
+
other.class == self.class &&
|
|
58
|
+
other.size == size &&
|
|
59
|
+
other.moves == moves
|
|
57
60
|
end
|
|
58
61
|
|
|
59
62
|
def empty_squares
|
|
@@ -9,13 +9,21 @@ module MattsTictactoeCore
|
|
|
9
9
|
|
|
10
10
|
def initialize(options = {})
|
|
11
11
|
@max_depth = options.fetch(:max_depth, 6)
|
|
12
|
-
@board = options
|
|
12
|
+
@board = build_board(options)
|
|
13
13
|
@player_x_type = options[:player_x_type]
|
|
14
14
|
@player_o_type = options[:player_o_type]
|
|
15
15
|
@computer_player = options.fetch(:computer_player, build_computer_player)
|
|
16
16
|
@human_player = options.fetch(:human_player, build_human_player)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
def build_board(options)
|
|
20
|
+
options.fetch(:board, build_new_board(options));
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def build_new_board(options)
|
|
24
|
+
Board.ofSize(options.fetch(:board_size, 3))
|
|
25
|
+
end
|
|
26
|
+
|
|
19
27
|
def next_player
|
|
20
28
|
next_player_type == :computer ? computer_player : human_player
|
|
21
29
|
end
|
|
@@ -43,7 +51,7 @@ module MattsTictactoeCore
|
|
|
43
51
|
end
|
|
44
52
|
|
|
45
53
|
def build_computer_player
|
|
46
|
-
ComputerPlayer.new
|
|
54
|
+
ComputerPlayer.new(max_depth: @max_depth)
|
|
47
55
|
end
|
|
48
56
|
|
|
49
57
|
def build_human_player
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: matts_tictactoe_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Glover
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|