Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 1 file changed
  • 0 comments
  • 1 contributor

Showing 1 changed file with 23 additions and 8 deletions. Show diff stats Hide diff stats

  1. 31  src/generalChess/v1Bobby.java
31  src/generalChess/v1Bobby.java
@@ -103,8 +103,9 @@ public void printBoard(){
103 103
 	
104 104
 	
105 105
 	//returns possible king moves
106  
-	public ArrayList<Point> kMoves(){
107  
-		ArrayList<Point> d=new ArrayList();
  106
+	public ArrayList<ArrayList> kMoves(){
  107
+		ArrayList<ArrayList> d=new ArrayList();
  108
+		ArrayList g=new ArrayList();
108 109
 		int x=-1;
109 110
 		int y=-1;
110 111
 		for(int j=0;j<8;j++){
@@ -115,6 +116,8 @@ public void printBoard(){
115 116
 				}
116 117
 			}
117 118
 		}
  119
+		g.add(b[x][y]);
  120
+		g.add(new Point(x, y));
118 121
 		if (x==-1||y==-1){
119 122
 			return null;
120 123
 		}
@@ -123,12 +126,13 @@ public void printBoard(){
123 126
 				for(int b=y-1;b<y+2;b++){
124 127
 					if(a>-1&&a<8&&b>-1&&b<8){
125 128
 						if(this.b[a][b].toString().charAt(1)=='X'||this.b[a][b].getColor()!=color){
126  
-							d.add(new Point(a,b));
  129
+							g.add(new Point(a,b));
127 130
 						}
128 131
 					}
129 132
 				}
130 133
 			}
131 134
 		}
  135
+		d.add(g);
132 136
 		return d;
133 137
 	}
134 138
 	
@@ -204,9 +208,9 @@ public void printBoard(){
204 208
 	}
205 209
 	
206 210
 	public void randomMove(){
207  
-		//makes an arraylist of all the arraylists for each point
  211
+		//makes an arraylist of all the arraylists of arraylists of moves for each piece - shit - 3d arraylist
208 212
 		//it's hierarchical - will choose from pawns first, then knights, then bishops, then rooks, then queens, then kings
209  
-		ArrayList<ArrayList> a=new ArrayList<ArrayList>();
  213
+		ArrayList<ArrayList<ArrayList>> a=new ArrayList<ArrayList<ArrayList>>();
210 214
 		a.add(pMoves());
211 215
 		a.add(nMoves());
212 216
 		a.add(bMoves());
@@ -216,12 +220,18 @@ public void randomMove(){
216 220
 		
217 221
 		//picks the next type of piece
218 222
 		int i=0;
219  
-		while(a.get(i).size()<=2)i++;
  223
+		while(a.get(i).size()==0)i++;
220 224
 		
221 225
 		Random r=new Random();
222  
-		Point p=new Point((Point)a.get(i).get(r.nextInt(a.get(i).size())));
  226
+		//random piece within the type of piece - i.e. pick a random pawn 
  227
+		int f=r.nextInt(a.get(i).size());
  228
+		//random point that that piece can move to
  229
+		int g=r.nextInt(a.get(i).get(f).size()-2)+2;
223 230
 		
224  
-
  231
+		Point start=new Point((Point)a.get(i).get(f).get(1));
  232
+		Point p=new Point((Point)a.get(i).get(f).get(g));
  233
+		
  234
+		move((int)start.getX(), (int)start.getY(), (int)p.getX(), (int)p.getY());
225 235
 	}
226 236
 	
227 237
 	
@@ -230,11 +240,15 @@ public static void main(String[] args){
230 240
 		Board d=new Board();
231 241
 		boolean color=true;
232 242
 		v1Bobby a=new v1Bobby(d, false);
  243
+		a.printBoard();
  244
+		a.randomMove();
  245
+		a.printBoard();
233 246
 		
234 247
 		/*
235 248
 		 * 4 move checkmate with white
236 249
 		 * */
237 250
 		
  251
+		/*
238 252
 		if(a.color==true){
239 253
 		a.move(4, 6, 4, 4);
240 254
 		a.printBoard();
@@ -245,6 +259,7 @@ public static void main(String[] args){
245 259
 		a.move(5, 5, 5, 1);
246 260
 		a.printBoard();
247 261
 		}
  262
+		*/
248 263
 				
249 264
 }
250 265
 	

No commit comments for this range

Something went wrong with that request. Please try again.