-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreversi.rb
83 lines (67 loc) · 1.44 KB
/
reversi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'bundler/setup'
require 'pp'
require 'terminal-table'
class Banmen
BLACK = '⚫️'
WHITE = '⚪️'
BLANK = '👽'
def initialize()
@banmen = Array.new(8) { Array.new(8) { BLANK } }
@banmen[3][3] = WHITE
@banmen[3][4] = BLACK
@banmen[4][3] = BLACK
@banmen[4][4] = WHITE
end
def banmen
pp @banmen
end
def put_black(x, y)
raise "Already exsists" if [WHITE, BLACK].include?(@banmen[x][y])
banmen[x][y] = BLACK
evaluation(x, y)
end
def put_white(x, y)
raise "Already exsists" if [WHITE, BLACK].include?(@banmen[x][y])
banmen[x][y] = WHITE
evaluation(x, y)
end
def evaluation(x, y)
iro = @banmen[x][y]
target_y = nil
(y + 1).upto(7) do |y2|
if @banmen[x][y2].nil?
break
end
if @banmen[x][y2] == iro
break
end
target_y = y2
# flag = true if @banmen[x][y2] != iro && @banmen[x][y2] != BLANK
end
@banmen[x][target_y] = reverse(@banmen[x][target_y])
end
def reverse(iro)
iro == BLACK ? WHITE : BLACK
end
def pretty_print
puts(::Terminal::Table.new(rows: @banmen))
end
end
class Player
def initialize(name, iro)
@name = name
@iro = iro
raise if @iro >= 2 || @iro < 0
end
end
class Game
def initialize
@banmen = Banmen.new(8, 8)
@current_player = Player.new()
end
end
banmen = Banmen.new
banmen.pretty_print
banmen.put_black(3, 2)
banmen.put_white(2, 2)
banmen.pretty_print