tttazures 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config.rb +14 -65
- data/lib/human_player.rb +4 -9
- 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: 275bf25f5feb16fb1bedc8058079290cfed0d42f
|
4
|
+
data.tar.gz: 68821836bbb6dd1a85c8066d3fd2e52ea12e6374
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 407733209f8104d0284fc8b84779978a5ff5eb36d4a4a9732394d430a850ddd146c1c6c4641e7a51ea24560c128c23378f8e0a512319a31605ebcc90e7783e50
|
7
|
+
data.tar.gz: f5949f23fc03faa97f08dfe17fcea28fe5a34a21d4aa8feb65016c0cf2ae7a6ab5ac8952f7f5c4b5a718f14aa1f4b392f1a241329dba091024809c2dc4d6e4da
|
data/lib/config.rb
CHANGED
@@ -3,76 +3,25 @@ require_relative './human_player'
|
|
3
3
|
require_relative './two_dimensional_board'
|
4
4
|
require_relative './three_dimensional_board'
|
5
5
|
|
6
|
-
class
|
7
|
-
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
case choice
|
15
|
-
when 0 then TwoDimensionalBoard.new 3
|
16
|
-
when 1 then TwoDimensionalBoard.new 4
|
17
|
-
when 2 then TwoDimensionalBoard.new 5
|
18
|
-
when 3 then ThreeDimensionalBoard.new 3
|
6
|
+
class Factory
|
7
|
+
|
8
|
+
def get_board board_type
|
9
|
+
case board_tupe
|
10
|
+
when :three_by_three then TwoDimensionalBoard.new 3
|
11
|
+
when :four_by_four then TwoDimensionalBoard.new 4
|
12
|
+
when :five_by_five then TwoDimensionalBoard.new 5
|
13
|
+
when :cube_three then ThreeDimensionalBoard.new 3
|
19
14
|
end
|
20
15
|
end
|
21
16
|
|
22
|
-
def
|
23
|
-
user_input = @console.query_user_for_game_type
|
24
|
-
players = {}
|
17
|
+
def get_player player_type, symbol
|
25
18
|
case user_input
|
26
|
-
when
|
27
|
-
|
28
|
-
|
29
|
-
when
|
30
|
-
players[:player1] = HumanPlayer.new(:x, @console)
|
31
|
-
players[:player2] = set_ai_difficulty(:o)
|
32
|
-
when 2
|
33
|
-
players[:player1] = set_ai_difficulty(:o)
|
34
|
-
players[:player2] = HumanPlayer.new(:x, @console)
|
35
|
-
when 3
|
36
|
-
players[:player1] = set_ai_difficulty(:x)
|
37
|
-
players[:player2] = set_ai_difficulty(:o)
|
19
|
+
when :human then HumanPlayer.new(symbol)
|
20
|
+
when :easy_ai then ComputerAI.new(symbol, 10)
|
21
|
+
when :medium_ai then ComputerAI.new(symbol, 50)
|
22
|
+
when :unbeatable_ai then ComputerAI.new(symbol, 100)
|
38
23
|
end
|
39
|
-
players
|
40
|
-
end
|
41
|
-
|
42
|
-
def set_ai_difficulty symbol
|
43
|
-
ai_difficulty_choice = get_ai_choice_from_user(symbol)
|
44
|
-
case ai_difficulty_choice
|
45
|
-
when 0 then ComputerAI.new(symbol, 10)
|
46
|
-
when 1 then ComputerAI.new(symbol, 50)
|
47
|
-
when 2 then ComputerAI.new(symbol, 100)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def get_board_choice
|
52
|
-
valid_choice = false
|
53
|
-
while valid_choice == false
|
54
|
-
choice = @console.query_user_for_board_type
|
55
|
-
if choice >= 0 && choice < 4 then valid_choice = true
|
56
|
-
else @console.print_user_input_error end
|
57
|
-
end
|
58
|
-
choice
|
59
24
|
end
|
25
|
+
end
|
60
26
|
|
61
|
-
def get_ai_choice_from_user symbol
|
62
|
-
valid_choice = false
|
63
|
-
while(!valid_choice)
|
64
|
-
choice = @console.query_user_for_ai_difficulty(symbol)
|
65
|
-
if choice < 3 && choice >= 0 then valid_choice = true end
|
66
|
-
end
|
67
|
-
choice
|
68
|
-
end
|
69
27
|
|
70
|
-
def get_board_printer board
|
71
|
-
if board.get_type == :two_dimensional_board
|
72
|
-
BoardPrinterTwoDim.new
|
73
|
-
elsif board.get_type == :three_dimensional_board
|
74
|
-
BoardPrinterThreeDim.new
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
data/lib/human_player.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
class HumanPlayer
|
2
2
|
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :symbol
|
4
4
|
|
5
|
-
def initialize player
|
6
|
-
@
|
7
|
-
@player = player
|
5
|
+
def initialize player
|
6
|
+
@symbol = symbol
|
8
7
|
end
|
9
8
|
|
10
9
|
def make_move board
|
11
|
-
|
12
|
-
while !valid_choice
|
13
|
-
choice = @console.query_user_for_choice(@player)
|
14
|
-
valid_choice = board.record_choice(choice, @player)
|
15
|
-
end
|
10
|
+
true
|
16
11
|
end
|
17
12
|
end
|