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
cbfabbd3
Commit
cbfabbd3
authored
7 years ago
by
dsjohns2
Browse files
Options
Downloads
Patches
Plain Diff
finish adding comments
parent
d75fb3ab
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Controller.java
+3
-0
3 additions, 0 deletions
Controller.java
Game.java
+28
-5
28 additions, 5 deletions
Game.java
Square.java
+6
-0
6 additions, 0 deletions
Square.java
View.java
+9
-0
9 additions, 0 deletions
View.java
with
46 additions
and
5 deletions
Controller.java
+
3
−
0
View file @
cbfabbd3
...
...
@@ -5,6 +5,9 @@ import java.applet.*;
import
java.awt.*
;
import
java.io.IOException
;
/**
* This is the Controller class in the MCV model
*/
public
class
Controller
extends
Applet
{
public
void
init
(
Game
game
){
try
{
...
...
This diff is collapsed.
Click to expand it.
Game.java
+
28
−
5
View file @
cbfabbd3
...
...
@@ -46,6 +46,14 @@ public class Game {
add_piece_to_location
(
5
,
4
,
"Z"
,
true
,
true
);
}
/**
* A helper method to add pieces to whereever on the board; useful for debugging
* @param x the x coord
* @param y the y coord
* @param name the name of the piece
* @param white whose turn
* @param occupied whether the square should be occupied
*/
public
void
add_piece_to_location
(
int
x
,
int
y
,
String
name
,
boolean
white
,
boolean
occupied
){
Square
new_square
=
new
Square
();
new_square
.
occupied
=
occupied
;
...
...
@@ -134,6 +142,18 @@ public class Game {
/* Check for end of game */
int
end_val
=
check_for_end_of_game
(
legal_moves
);
if
(
end_val
>
0
){
return
end_val
;
}
/* Game continues */
this
.
board
=
pick_move
(
legal_moves
);
white_turn
=
!
white_turn
;
return
-
1
;
}
public
int
check_for_end_of_game
(
Square
[][][]
legal_moves
){
if
(
legal_moves
.
length
==
0
){
boolean
stalemate_flag
=
true
;
List
<
Square
[][]>
next_move_legal_moves
=
get_legal_moves
(!
white_turn
,
this
.
board
);
...
...
@@ -161,9 +181,6 @@ public class Game {
return
2
;
}
}
/* Game continues */
this
.
board
=
pick_move
(
legal_moves
);
white_turn
=
!
white_turn
;
return
-
1
;
}
...
...
@@ -181,6 +198,12 @@ public class Game {
return
(
legal_moves
[
n
]);
}
/**
* A method to get the legal moves and then remove the moves that end with the play still in check
* @param white whose turn
* @param board the state of the board
* @return the list of truely legal moves
*/
public
Square
[][][]
get_all_moves
(
boolean
white
,
Square
[][]
board
){
List
<
Square
[][]>
legal_moves
=
get_legal_moves
(
white
,
board
);
Square
[][][]
new_legal_moves
=
remove_moves_into_check
(
white
,
legal_moves
);
...
...
@@ -222,8 +245,8 @@ public class Game {
/**
* A method to remove the legal moves ending in check
* @param legal_moves
* @return
* @param legal_moves
the "legal moves" coming in
* @return
the legal moves that don't end with check
*/
public
Square
[][][]
remove_moves_into_check
(
boolean
white
,
List
<
Square
[][]>
legal_moves
){
for
(
int
i
=
0
;
i
<
legal_moves
.
size
();
i
++){
...
...
This diff is collapsed.
Click to expand it.
Square.java
+
6
−
0
View file @
cbfabbd3
...
...
@@ -101,6 +101,12 @@ public class Square {
return
squares
.
toArray
(
new
int
[
squares
.
size
()][
2
]);
}
/**
* A helper method to add legal squares to the square list
* @param new_x the x coord
* @param new_y the y coord
* @return the list of legal square tuples
*/
public
List
<
int
[]>
legal_square_addition
(
int
new_x
,
int
new_y
){
List
<
int
[]>
squares
=
new
Vector
<
int
[]>();
int
[]
square
=
new
int
[
2
];
...
...
This diff is collapsed.
Click to expand it.
View.java
+
9
−
0
View file @
cbfabbd3
...
...
@@ -11,7 +11,16 @@ import java.io.IOException;
import
java.util.ArrayList
;
import
java.util.Vector
;
import
javax.swing.*
;
/**
* This is the View class in the MCV model
*/
public
class
View
{
/**
* This is the default constructor that takes in the model
* @param game this is the model to be displayed
* @throws IOException
*/
View
(
Game
game
)
throws
IOException
{
JFrame
f
=
new
JFrame
(
"Chess"
);
JPanel
panel
=
new
JPanel
();
...
...
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