nraya 0.0.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 +7 -0
- data/bin/nraya +28 -0
- data/lib/board.rb +67 -0
- data/lib/main.rb +60 -0
- data/lib/nrayaex.rb +4 -0
- data/lib/player.rb +53 -0
- metadata +50 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1c1802e4a9d9d4f368836a482f9dae706aae585c
|
|
4
|
+
data.tar.gz: 55b51135ed17a5d74c44297e4f5fc06f02ced012
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3c636c411ab031a54c4d94eaba75acb902652fbd43bc88cf9d4d4ffe7e194f187565cdb54dca58dd1a03a1bcda6beee10e6d6cdaeac1597b585ae408b9a4d976
|
|
7
|
+
data.tar.gz: 324d2f24acaf843985f7194b352692c04482aa50781472c662ac8e2688581d6ffdbc3b894b8ae82aac5c033bc07fd390862920e8d589b0df8a23fbf712610845
|
data/bin/nraya
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'main'
|
|
5
|
+
require 'board'
|
|
6
|
+
require 'nrayaex'
|
|
7
|
+
|
|
8
|
+
$stdout.print "> Give me the n: "
|
|
9
|
+
$stdout.flush
|
|
10
|
+
n = gets.to_i
|
|
11
|
+
|
|
12
|
+
$stdout.print "> Give me the number of players: "
|
|
13
|
+
$stdout.flush
|
|
14
|
+
x = gets.to_i
|
|
15
|
+
|
|
16
|
+
$game = Game.new(n, x)
|
|
17
|
+
|
|
18
|
+
begin
|
|
19
|
+
$game.initGame()
|
|
20
|
+
rescue WeHaveWin
|
|
21
|
+
puts ''
|
|
22
|
+
rescue BigNumber
|
|
23
|
+
puts "Exception: Number of selected row too big"
|
|
24
|
+
rescue NoMoreTokens
|
|
25
|
+
puts "Exception: Upps... No more tokens found - No one wins :("
|
|
26
|
+
rescue
|
|
27
|
+
puts "Exception: 404 - Not found"
|
|
28
|
+
end
|
data/lib/board.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'matrix'
|
|
2
|
+
require 'nrayaex'
|
|
3
|
+
|
|
4
|
+
class Board
|
|
5
|
+
attr_reader :cols, :rows, :matriz
|
|
6
|
+
def initialize(cols, rows)
|
|
7
|
+
@cols = cols
|
|
8
|
+
@rows = rows
|
|
9
|
+
setMatriz()
|
|
10
|
+
printBoard()
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
def setMatriz
|
|
15
|
+
$matriz = Array.new(@rows) {Array.new(@cols, '|')}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def printRows
|
|
19
|
+
i = 1
|
|
20
|
+
while i < (rows-1) do
|
|
21
|
+
if i < 10 then print " #{i} "
|
|
22
|
+
else print " #{i}"
|
|
23
|
+
end
|
|
24
|
+
i += 1
|
|
25
|
+
end
|
|
26
|
+
puts ''
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def printMatriz
|
|
30
|
+
$matriz.each do |i|
|
|
31
|
+
i.each do |j|
|
|
32
|
+
print " #{j} "
|
|
33
|
+
end
|
|
34
|
+
puts ''
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
public
|
|
39
|
+
def printBoard
|
|
40
|
+
printRows()
|
|
41
|
+
printMatriz()
|
|
42
|
+
puts ''
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def setPoint(x, sym)
|
|
46
|
+
point = 0
|
|
47
|
+
if x < @rows
|
|
48
|
+
point = @cols+1
|
|
49
|
+
x -= 1
|
|
50
|
+
while $matriz[point][x] != '|' do
|
|
51
|
+
point = point - 1
|
|
52
|
+
end
|
|
53
|
+
$matriz[point][x] = sym
|
|
54
|
+
system 'clear' or system 'cls'
|
|
55
|
+
printBoard()
|
|
56
|
+
else
|
|
57
|
+
puts "Exception: Number of selected row too big"
|
|
58
|
+
raise BigNumber
|
|
59
|
+
end
|
|
60
|
+
return point
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def getMatriz
|
|
64
|
+
return $matriz
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
data/lib/main.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'board'
|
|
2
|
+
require 'player'
|
|
3
|
+
require 'nrayaex'
|
|
4
|
+
|
|
5
|
+
class Game
|
|
6
|
+
attr_reader :cols, :rows, :n, :x, :tokens
|
|
7
|
+
def initialize(n, players)
|
|
8
|
+
@cols = 2*n+1
|
|
9
|
+
@rows = 2*n-1
|
|
10
|
+
@n = n
|
|
11
|
+
@players = players
|
|
12
|
+
@tokens = ((2*n-1)*(2*n-2)/players)
|
|
13
|
+
@playersArray = Array.new()
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initGame
|
|
17
|
+
createPlayers()
|
|
18
|
+
$board = Board.new(@rows, @cols)
|
|
19
|
+
turns()
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def createPlayers
|
|
23
|
+
i = 0
|
|
24
|
+
symbols = Array.new()
|
|
25
|
+
until i >= @players
|
|
26
|
+
$stdout.print "> Enter your name player #{i+1}: "
|
|
27
|
+
$stdout.flush
|
|
28
|
+
name = gets
|
|
29
|
+
$stdout.print "> Enter your symbol #{name.chomp}: "
|
|
30
|
+
$stdout.flush
|
|
31
|
+
sym = gets
|
|
32
|
+
player = Player.new(name, sym.chop!, @tokens)
|
|
33
|
+
@playersArray.push(player)
|
|
34
|
+
i += 1
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def turns
|
|
39
|
+
player = @playersArray.shift
|
|
40
|
+
if player.tokens != 0
|
|
41
|
+
$stdout.print "> Enter the column that you like play "
|
|
42
|
+
$stdout.print "(#{player.name.chomp} :: #{player.sym} :: #{player.tokens}): "
|
|
43
|
+
$stdout.flush
|
|
44
|
+
x = gets.to_i
|
|
45
|
+
y = $board.setPoint(x, player.sym)
|
|
46
|
+
player.setPosition(x,y)
|
|
47
|
+
player.getPositions()
|
|
48
|
+
player.restToken()
|
|
49
|
+
@playersArray.push(player)
|
|
50
|
+
else
|
|
51
|
+
raise NoMoreTokens
|
|
52
|
+
end
|
|
53
|
+
if player.checkWin == true then
|
|
54
|
+
puts "Congrats #{player.name.chomp}! You won on nraya game!"
|
|
55
|
+
raise WeHaveWin
|
|
56
|
+
else
|
|
57
|
+
turns()
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/lib/nrayaex.rb
ADDED
data/lib/player.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'nrayaex'
|
|
2
|
+
|
|
3
|
+
class Player
|
|
4
|
+
attr_reader :name, :sym, :tokens
|
|
5
|
+
def initialize(name, sym, tokens)
|
|
6
|
+
@name = name
|
|
7
|
+
@sym = sym
|
|
8
|
+
@tokens = tokens
|
|
9
|
+
@positions = Array.new()
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
public
|
|
13
|
+
def restToken
|
|
14
|
+
@tokens -= 1
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def setPosition(x,y)
|
|
18
|
+
point = [x,y]
|
|
19
|
+
@positions.push(point)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def getPositions
|
|
23
|
+
return @positions
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def checkWin
|
|
27
|
+
#V: Vertical - #H: Horizontal - DR: Diagonal Right - DL: Diagonal Left
|
|
28
|
+
i, j, k, v, h, dr, dl = [0]*7
|
|
29
|
+
matriz = $board.getMatriz
|
|
30
|
+
until i >= $game.rows do
|
|
31
|
+
j = 0
|
|
32
|
+
until j >= $game.cols do
|
|
33
|
+
if matriz[j][i] == @sym then v += 1 else v = 0 end
|
|
34
|
+
if matriz[i+2][j] == @sym then h += 1 else h = 0 end
|
|
35
|
+
if matriz[i][j] == @sym && i > ($game.rows - $game.n + 1) then
|
|
36
|
+
k = 0
|
|
37
|
+
until k >= $game.n
|
|
38
|
+
if matriz[i+k][j+k] == @sym then dl += 1 else dl = 0 end
|
|
39
|
+
if matriz[i+k][j-k] == @sym then dr += 1 else dr = 0 end
|
|
40
|
+
k += 1
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
if ( v == $game.n || h == $game.n || dr == $game.n || dl == $game.n ) then
|
|
44
|
+
return true
|
|
45
|
+
end
|
|
46
|
+
j += 1
|
|
47
|
+
end
|
|
48
|
+
i += 1
|
|
49
|
+
h = 0
|
|
50
|
+
end
|
|
51
|
+
return false
|
|
52
|
+
end
|
|
53
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nraya
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.5
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Josue Daniel Bustamante - Santiago Baena
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: The 3 or 4 connect game on a new and better n game version!
|
|
14
|
+
email: jbusta16@eafit.edu.co
|
|
15
|
+
executables:
|
|
16
|
+
- nraya
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/nraya
|
|
21
|
+
- lib/board.rb
|
|
22
|
+
- lib/main.rb
|
|
23
|
+
- lib/nrayaex.rb
|
|
24
|
+
- lib/player.rb
|
|
25
|
+
homepage: http://github.com/JosueDanielBust/nraya
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata: {}
|
|
29
|
+
post_install_message: Thanks for installing nraya! We think you like this awesome
|
|
30
|
+
game!
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubyforge_project:
|
|
46
|
+
rubygems_version: 2.4.6
|
|
47
|
+
signing_key:
|
|
48
|
+
specification_version: 4
|
|
49
|
+
summary: A 4 connect game on a (n) game version!
|
|
50
|
+
test_files: []
|