-
Notifications
You must be signed in to change notification settings - Fork 2
/
tile.rb
156 lines (123 loc) · 4.95 KB
/
tile.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
=begin
ruby_chess
The Chess Board game implemented in the metalanguage ruby
Using the mighty GTK2 library
Copyright (C) 2006 Sébastien Boisvert
http://sebhtml.blogspot.com/
Sebastien.Boisvert<AT>USherbrooke<DOT>CA
This software is released under the GPL version 2 (1991)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
An online plain text version is available here:
http://www.gnu.org/licenses/gpl.txt
=end
require_relative 'board'
class Tile
def to_s
location
end
def initialize row, col
@row = row
@col = col
@location = @@locations[row][col]
end
def == j
@row == j.row && @col == j.col
end
def self.locations
@@locations
end
def location
@location
end
def row
@row
end
def col
@col
end
def self.build_locations
@@locations = {}
@@locations[Board::ROW_8] = {}
@@locations[Board::ROW_7] = {}
@@locations[Board::ROW_6] = {}
@@locations[Board::ROW_5] = {}
@@locations[Board::ROW_4] = {}
@@locations[Board::ROW_3] = {}
@@locations[Board::ROW_2] = {}
@@locations[Board::ROW_1] = {}
@@locations[Board::ROW_8][Board::COL_A] = "A8"
@@locations[Board::ROW_8][Board::COL_B] = "B8"
@@locations[Board::ROW_8][Board::COL_C] = "C8"
@@locations[Board::ROW_8][Board::COL_D] = "D8"
@@locations[Board::ROW_8][Board::COL_E] = "E8"
@@locations[Board::ROW_8][Board::COL_F] = "F8"
@@locations[Board::ROW_8][Board::COL_G] = "G8"
@@locations[Board::ROW_8][Board::COL_H] = "H8"
@@locations[Board::ROW_7][Board::COL_A] = "A7"
@@locations[Board::ROW_7][Board::COL_B] = "B7"
@@locations[Board::ROW_7][Board::COL_C] = "C7"
@@locations[Board::ROW_7][Board::COL_D] = "D7"
@@locations[Board::ROW_7][Board::COL_E] = "E7"
@@locations[Board::ROW_7][Board::COL_F] = "F7"
@@locations[Board::ROW_7][Board::COL_G] = "G7"
@@locations[Board::ROW_7][Board::COL_H] = "H7"
@@locations[Board::ROW_6][Board::COL_A] = "A6"
@@locations[Board::ROW_6][Board::COL_B] = "B6"
@@locations[Board::ROW_6][Board::COL_C] = "C6"
@@locations[Board::ROW_6][Board::COL_D] = "D6"
@@locations[Board::ROW_6][Board::COL_E] = "E6"
@@locations[Board::ROW_6][Board::COL_F] = "F6"
@@locations[Board::ROW_6][Board::COL_G] = "G6"
@@locations[Board::ROW_6][Board::COL_H] = "H6"
@@locations[Board::ROW_5][Board::COL_A] = "A5"
@@locations[Board::ROW_5][Board::COL_B] = "B5"
@@locations[Board::ROW_5][Board::COL_C] = "C5"
@@locations[Board::ROW_5][Board::COL_D] = "D5"
@@locations[Board::ROW_5][Board::COL_E] = "E5"
@@locations[Board::ROW_5][Board::COL_F] = "F5"
@@locations[Board::ROW_5][Board::COL_G] = "G5"
@@locations[Board::ROW_5][Board::COL_H] = "H5"
@@locations[Board::ROW_4][Board::COL_A] = "A4"
@@locations[Board::ROW_4][Board::COL_B] = "B4"
@@locations[Board::ROW_4][Board::COL_C] = "C4"
@@locations[Board::ROW_4][Board::COL_D] = "D4"
@@locations[Board::ROW_4][Board::COL_E] = "E4"
@@locations[Board::ROW_4][Board::COL_F] = "F4"
@@locations[Board::ROW_4][Board::COL_G] = "G4"
@@locations[Board::ROW_4][Board::COL_H] = "H4"
@@locations[Board::ROW_3][Board::COL_A] = "A3"
@@locations[Board::ROW_3][Board::COL_B] = "B3"
@@locations[Board::ROW_3][Board::COL_C] = "C3"
@@locations[Board::ROW_3][Board::COL_D] = "D3"
@@locations[Board::ROW_3][Board::COL_E] = "E3"
@@locations[Board::ROW_3][Board::COL_F] = "F3"
@@locations[Board::ROW_3][Board::COL_G] = "G3"
@@locations[Board::ROW_3][Board::COL_H] = "H3"
@@locations[Board::ROW_2][Board::COL_A] = "A2"
@@locations[Board::ROW_2][Board::COL_B] = "B2"
@@locations[Board::ROW_2][Board::COL_C] = "C2"
@@locations[Board::ROW_2][Board::COL_D] = "D2"
@@locations[Board::ROW_2][Board::COL_E] = "E2"
@@locations[Board::ROW_2][Board::COL_F] = "F2"
@@locations[Board::ROW_2][Board::COL_G] = "G2"
@@locations[Board::ROW_2][Board::COL_H] = "H2"
@@locations[Board::ROW_1][Board::COL_A] = "A1"
@@locations[Board::ROW_1][Board::COL_B] = "B1"
@@locations[Board::ROW_1][Board::COL_C] = "C1"
@@locations[Board::ROW_1][Board::COL_D] = "D1"
@@locations[Board::ROW_1][Board::COL_E] = "E1"
@@locations[Board::ROW_1][Board::COL_F] = "F1"
@@locations[Board::ROW_1][Board::COL_G] = "G1"
@@locations[Board::ROW_1][Board::COL_H] = "H1"
end
build_locations
end