Skip to content
Snippets Groups Projects
Commit cbfabbd3 authored by dsjohns2's avatar dsjohns2
Browse files

finish adding comments

parent d75fb3ab
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
......@@ -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++){
......
......@@ -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];
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment