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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9b3823f8f4c11cb7b42db9a31b4d4fccf4c5d2e
4
- data.tar.gz: '08090c8cca6b1813388e92defa0c0db1f0efe63f'
3
+ metadata.gz: ba143b33d21600006aa31970563bc8cb38ec200e
4
+ data.tar.gz: 43753236d8c0e5d4e953b93465e9f171cc6638c4
5
5
  SHA512:
6
- metadata.gz: 35f02be1fe539a7e6ecd160ae2d0cbe1bf4d88b4db07e0eb83be8ad26ff68dcd02c0dd9839b2f5d91e5291aff51b08e277741763418c774756d7d0511417e973
7
- data.tar.gz: 637ce39177f3c77e7dfdee24e3a8fc50d8d0c4349f3d69db214c0278d02cd84e4985192beeb5c6b31d7243074228d31043ac945b58dada9ec42e9a1f9f414095
6
+ metadata.gz: e9ede84d84dfcf7984583c9f96c9c989268155af12772b1486a945f0c221bddb5fba7b28a6813020bb229364a9f8f1e3e8003c777de5f5106746f76127ae9236
7
+ data.tar.gz: f564afe9f6f3048ffdd1da8f023e379faf647caac08743d9e1927dac8dbbefede1da8cdb4e28ce1499658b8c4e2943bb33d8193cd591b5c887c63c78fee91520
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- matts_tictactoe_core (0.1.0)
4
+ matts_tictactoe_core (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -3,10 +3,15 @@ require "matts_tictactoe_core/lines"
3
3
  module MattsTictactoeCore
4
4
  class Board
5
5
 
6
- attr_reader :moves
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 && other.moves == moves
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.fetch(:board, Board.new)
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
@@ -1,3 +1,3 @@
1
1
  module MattsTictactoeCore
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-09-28 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler