x_and_os 0.0.2 → 0.0.3

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: 26abf99b399b44f43e52de5048bf505d0ba28db0
4
- data.tar.gz: 5f50b16285f9519b984be7590adbf5ac829c5001
3
+ metadata.gz: 0443f74019385ca1eb86756fa71d1aa789421ab2
4
+ data.tar.gz: 6bf57de3a7dda66671b2a214cd4aaab3c8e3fdd2
5
5
  SHA512:
6
- metadata.gz: f8ab4f63dcd2fbdfd5f8388a2f9aafd6897a6773c6d23e4fa13fceb14011c613aba05a10af180f95eaa233656dcd87ea57f25d6170ab6cc2121f36664c042159
7
- data.tar.gz: 2a47b86dc429bfeaf25ef08a3c9caabb358d6a39e32d8e3e6c23d7dc7385f0ca417ce5a0b29cf49cab4d5d4f1d6e4799e11a987f93828c09363f6f501842602a
6
+ metadata.gz: f6049143108f22d87912abc75ffad31117f4d733131639f01081c06ab0e5879c551ceab2ea88a252d4f01cb6e40ad1ac404ee00ba31528d270e6161ee82fa855
7
+ data.tar.gz: 8258c7b4a716be3f82e2bc9ba15ee40f5fbef088831dcd3aec47d6d53c190db6c95926d2d38cd7a0cb37a9fce53b02fce45fe1cd8f3bbc410d0fc98908d72f14
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # XAndOs
2
2
 
3
- XAndOs provides the basic structure and game logic to easily create the game Tic Tac Toe.
4
- It also comes with a mini CLA to play Tic Tac Toe in the command line.
3
+ x_and_os provides the basic structure and game logic to easily create a Tic Tac Toe game.
4
+ It also comes with a mini command line app to play Tic Tac Toe / x and os.
5
5
 
6
6
  ## Installation
7
7
 
@@ -21,16 +21,112 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
+ ```ruby
25
+ require 'x_and_os'
26
+ ```
27
+
24
28
  ### Game
25
- TODO
29
+ Used to manage the basic state of game.
30
+
31
+ Initialize a new game with:
32
+
33
+ ```ruby
34
+ XAndOS::Game.new
35
+ ```
36
+ or
37
+
38
+ ```ruby
39
+ include XAndOs
40
+
41
+ Game.new
42
+
43
+ ```
44
+ By default `Game.new` will create a new game object that uses the XAndOs::Board that has 3rows and 3columns.
45
+
46
+ It is possible to set rows and columns
47
+ when instantiating a new game
48
+
49
+ ```ruby
50
+ XAndOs::Game.new(rows: 4, columns: 3)
51
+
52
+ ```
53
+
54
+ If you wish to use a different game board (not recommended):
55
+
56
+ ```ruby
57
+ custom_game_board = Board.new
58
+
59
+ XAndOs::Game.new(board: custom_game_board)
60
+ ```
61
+
62
+ #### game API
63
+
64
+ `add_move` takes a cell number and a marker(optional) to put in the cell.
65
+
66
+ ```ruby
67
+ @game = XAndOs::Game.new
68
+
69
+ @game.add_move(5, 'x')
70
+ @game.add_move(1, 'o')
71
+ ```
72
+ or
73
+
74
+ ```ruby
75
+ @game.add_move(5)
76
+ @game.add_move(1)
77
+
78
+ ```
79
+ Will result in a board with a grid that looks like this.
80
+
81
+ ```ruby
82
+ @game.board.grid # [['o',' ',' '],
83
+ # [' ','x',' '],
84
+ # [' ',' ',' ']]
85
+ ```
86
+
87
+ Cell numbers map left to right as such :
88
+ ```
89
+ [[1,2,3],
90
+ [4,5,6],
91
+ [7,8,9]]
92
+ ```
93
+
94
+
95
+ `get_marker` returns the value of the next marker 'X' or 'O' depending on number of turns made. First move is always 'X'
96
+
97
+ `winner?` returns `true` if there is a complete line e.g
98
+
99
+ ```
100
+ # x | | o
101
+ # --------
102
+ # o | x |
103
+ # --------
104
+ # | | x
105
+ ```
106
+
107
+
108
+ `draw?` will return `true` when there are no moves available.
109
+
110
+
26
111
  ### Board
27
112
  TODO
28
113
  ### Game Mastery
29
114
  TODO
30
115
 
31
116
  ### Command Line App
32
- You can use XAndOs to play Tic Tac Toe in the command line
33
- `x_and_os`
117
+ You can use x_and_os to play Tic Tac Toe / X and Os in the command line.
118
+
119
+ After installing the gem run :
120
+
121
+ $ x_and_os
122
+
123
+ And then follow the menu options.
124
+
125
+ - Quick game sets up a You vs Computer on 3x3 game board.
126
+ - settings allows the user to
127
+ - pick two players (either player(human) or computer)
128
+ - choose a grid size to play on. e.g 3x3 or 5x5
129
+ - The computer player uses the GameMaster class to be make the best possible moves (unbeatable on 3x3 board)
34
130
 
35
131
  ## Development
36
132
 
@@ -12,7 +12,7 @@ module XAndOs
12
12
  move = win || block || fork_move || force_block || block_fork
13
13
  return move if move
14
14
 
15
- if first_move
15
+ if first_move?
16
16
  1
17
17
  else
18
18
  center || corner || available_moves.sample
@@ -50,10 +50,10 @@ module XAndOs
50
50
  end
51
51
 
52
52
  def opponent_moves
53
- (1..9).to_a - (moves_made + available_moves)
53
+ (1..total_cells).to_a - (moves_made + available_moves)
54
54
  end
55
55
 
56
- def first_move
56
+ def first_move?
57
57
  available_moves.size == total_cells
58
58
  end
59
59
 
@@ -130,9 +130,14 @@ module XAndOs
130
130
  end
131
131
 
132
132
  def corner_moves
133
- # To be improved to dynamically work out corners
134
- # and move logic to board
135
- [1,3,7,9]
133
+ total_columns = mastery_board.columns
134
+
135
+ top_left = 1
136
+ top_right = mastery_board.columns
137
+ bottom_left = (total_cells - total_columns) + 1
138
+ bottom_right = total_cells
139
+
140
+ [top_left, top_right, bottom_left, bottom_right]
136
141
  end
137
142
 
138
143
  end
@@ -1,3 +1,3 @@
1
1
  module XAndOs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x_and_os
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler