-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.swift
More file actions
131 lines (117 loc) · 2.61 KB
/
main.swift
File metadata and controls
131 lines (117 loc) · 2.61 KB
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
var turn = 0
class Board {
var boardPieces: [[[StaticChessPiece]]] = [[[],[],[],[],[],[],[],[]],[[],[],[],[],[],[],[],[]],[[],[],[],[],[],[],[],[]],[[],[],[],[],[],[],[],[]],[[],[],[],[],[],[],[],[]],[[],[],[],[],[],[],[],[]],[[],[],[],[],[],[],[],[]],[[],[],[],[],[],[],[],[]]]
func setBoard(setX: Int, setY: Int, piece: StaticChessPiece) {
boardPieces[setX][setY].append(piece)
}
}
class StaticChessPiece {
var color: Bool = true
var x: Int = 0
var y: Int = 0
var num: Int = 0
var whoseTurn = true
init(color: Bool, x: Int, y: Int, num: Int) {
self.color = color
self.x = x
self.y = y
self.num = num
}
func isPossible(_ x: Int, _ y: Int, _ toX: Int, _ toY: Int, _ color: Bool) -> Bool {
return true
}
func move(x: Int, y: Int, toX: Int, toY: Int) {
//Empty method for chessBoard to access, changes in ChessPieces.
}
/*func inTheWay(between: [Int], current: Int) {
for place in between.count {
if
}
}*/
}
var chessBoard = Board()
class ChessPiece: StaticChessPiece {
override func move(x: Int, y: Int, toX: Int, toY: Int) {
if turn % 2 == 0 {
whoseTurn = true
} else {
whoseTurn = false
}
if isPossible(x, y, toX, toY, whoseTurn) {
chessBoard.boardPieces[toX][toY][0] = self
} else {
print("move not possible")
}
}
}
//Piece Classes
class Pawn: ChessPiece {
override func isPossible(_ x: Int, _ y: Int, _ toX: Int, _ toY: Int, _ color: Bool) -> Bool {
if color == true {
if turn == 0 {
if toY == y + 1 || toY == y + 2 {
return true
}
} else {
if toY == y + 1 {
return true
}
}
} else {
if turn == 1 {
if toY == y - 1 || toY == y - 2 {
return true
}
} else {
if toY == y - 1 {
return true
}
}
}
return false
}
}
class Bishop: ChessPiece {
override func isPossible(_ x: Int, _ y: Int, _ toX: Int, _ toY: Int, _ color: Bool) -> Bool {
if toX - x == toY - y {
return true
} else {
return false
}
}
}
class Rook: ChessPiece {
override func isPossible(_ x: Int, _ y: Int, _ toX: Int, _ toY: Int, _ color: Bool) -> Bool {
if toX - x == 0 {
if toY - y != 0 {
return true
}
else {
return false
}
}
else if toY - y == 0 {
if toX - x != 0 {
return true
}
else {
return false
}
}
}
//Board Setup
var BR1: StaticChessPiece = Rook(color: false, x: 0, y: 0, num: 1)
chessBoard.setBoard(setX: 0, setY: 0, piece: BR1)
/*
var boardPieces: [[[ChessPiece]]] =
[
[[],[],[],[],[],[],[],[]],
[[],[],[],[],[],[],[],[]],
[[],[],[],[],[],[],[],[]],
[[],[],[],[],[],[],[],[]],
[[],[],[],[],[],[],[],[]],
[[],[],[],[],[],[],[],[]],
[[],[],[],[],[],[],[],[]],
[[],[],[],[],[],[],[],[]]
]
*/