Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Assignment1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dsjohns2
Assignment1
Commits
1c6addee
Commit
1c6addee
authored
7 years ago
by
dsjohns2
Browse files
Options
Downloads
Patches
Plain Diff
add custom pieces
parent
51119fd8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Game.java
+6
-4
6 additions, 4 deletions
Game.java
Main.java
+1
-1
1 addition, 1 deletion
Main.java
Square.java
+43
-0
43 additions, 0 deletions
Square.java
with
50 additions
and
5 deletions
Game.java
+
6
−
4
View file @
1c6addee
...
@@ -40,8 +40,10 @@ public class Game {
...
@@ -40,8 +40,10 @@ public class Game {
board
[
i
][
j
]
=
new_square
;
board
[
i
][
j
]
=
new_square
;
}
}
}
}
add_piece_to_location
(
5
,
2
,
"Q"
,
false
,
true
);
add_piece_to_location
(
2
,
3
,
"A"
,
false
,
true
);
add_piece_to_location
(
6
,
3
,
""
,
true
,
false
);
add_piece_to_location
(
2
,
4
,
"B"
,
false
,
true
);
add_piece_to_location
(
5
,
3
,
"A"
,
true
,
true
);
add_piece_to_location
(
5
,
4
,
"B"
,
true
,
true
);
}
}
public
void
add_piece_to_location
(
int
x
,
int
y
,
String
name
,
boolean
white
,
boolean
occupied
){
public
void
add_piece_to_location
(
int
x
,
int
y
,
String
name
,
boolean
white
,
boolean
occupied
){
...
@@ -124,12 +126,12 @@ public class Game {
...
@@ -124,12 +126,12 @@ public class Game {
public
int
make_move
()
throws
InterruptedException
{
public
int
make_move
()
throws
InterruptedException
{
Square
[][][]
legal_moves
=
get_all_moves
(
white_turn
,
this
.
board
);
Square
[][][]
legal_moves
=
get_all_moves
(
white_turn
,
this
.
board
);
/*
for
(
int
i
=
0
;
i
<
legal_moves
.
length
;
i
++){
for
(
int
i
=
0
;
i
<
legal_moves
.
length
;
i
++){
TimeUnit
.
SECONDS
.
sleep
(
1
);
TimeUnit
.
SECONDS
.
sleep
(
1
);
print_board
(
legal_moves
[
i
]);
print_board
(
legal_moves
[
i
]);
}
}
*/
/* Check for end of game */
/* Check for end of game */
if
(
legal_moves
.
length
==
0
){
if
(
legal_moves
.
length
==
0
){
...
...
This diff is collapsed.
Click to expand it.
Main.java
+
1
−
1
View file @
1c6addee
...
@@ -16,7 +16,7 @@ public class Main {
...
@@ -16,7 +16,7 @@ public class Main {
int
end_of_game
=
-
1
;
int
end_of_game
=
-
1
;
while
(
end_of_game
==
-
1
){
while
(
end_of_game
==
-
1
){
end_of_game
=
my_game
.
make_move
();
end_of_game
=
my_game
.
make_move
();
//
TimeUnit.SECONDS.sleep(
1
);
TimeUnit
.
SECONDS
.
sleep
(
5
);
my_game
.
print_board
(
my_game
.
board
);
my_game
.
print_board
(
my_game
.
board
);
}
}
if
(
end_of_game
==
0
){
if
(
end_of_game
==
0
){
...
...
This diff is collapsed.
Click to expand it.
Square.java
+
43
−
0
View file @
1c6addee
...
@@ -61,6 +61,12 @@ public class Square {
...
@@ -61,6 +61,12 @@ public class Square {
else
if
(
this
.
name
==
"Q"
){
else
if
(
this
.
name
==
"Q"
){
return
queen_squares
(
board
);
return
queen_squares
(
board
);
}
}
else
if
(
this
.
name
==
"A"
){
return
A_squares
(
board
);
}
else
if
(
this
.
name
==
"B"
){
return
B_squares
(
board
);
}
else
{
else
{
return
king_squares
(
board
);
return
king_squares
(
board
);
}
}
...
@@ -261,6 +267,43 @@ public class Square {
...
@@ -261,6 +267,43 @@ public class Square {
return
squares
.
toArray
(
new
int
[
squares
.
size
()][
2
]);
return
squares
.
toArray
(
new
int
[
squares
.
size
()][
2
]);
}
}
/**
* A helper method returning the possible locations of A piece
* @param board the current state of the board
* @return an array of tuples representing x and y, the locations that can be reached
*/
public
int
[][]
A_squares
(
Square
[][]
board
)
{
List
<
int
[]>
squares
=
new
Vector
<
int
[]>();
int
x
=
this
.
x
;
int
y
=
this
.
y
;
for
(
int
i
=
0
;
i
<=
7
;
i
++){
for
(
int
j
=
0
;
j
<=
7
;
j
++){
if
(!(
i
==
x
&&
j
==
y
)
&&
board
[
i
][
j
].
name
!=
"K"
&&
board
[
i
][
j
].
name
!=
"A"
)
{
squares
.
addAll
(
square_checker
(
board
,
x
,
y
,
i
,
j
));
}
}
}
return
squares
.
toArray
(
new
int
[
squares
.
size
()][
2
]);
}
/**
* A helper method returning the possible locations of B piece
* @param board the current state of the board
* @return an array of tuples representing x and y, the locations that can be reached
*/
public
int
[][]
B_squares
(
Square
[][]
board
)
{
List
<
int
[]>
squares
=
new
Vector
<
int
[]>();
int
x
=
this
.
x
;
int
y
=
this
.
y
;
if
(
x
+
y
%
2
==
0
)
{
squares
.
addAll
(
Arrays
.
asList
(
bishop_squares
(
board
)));
}
else
{
squares
.
addAll
(
Arrays
.
asList
(
rook_squares
(
board
)));
}
return
squares
.
toArray
(
new
int
[
squares
.
size
()][
2
]);
}
/**
/**
* A helper method returning the possible locations of a king
* A helper method returning the possible locations of a king
* @param board the current state of the board
* @param board the current state of the board
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment