From 984c37a833f0727ba8a208406a25cb657c48da86 Mon Sep 17 00:00:00 2001 From: CT Date: Thu, 23 Apr 2026 23:07:22 -0500 Subject: [PATCH] added rook, created bishop file --- Bishop.java | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ Board.class | Bin 980 -> 1067 bytes Board.java | 4 +-- Knight.class | Bin 1599 -> 1711 bytes Pawn.class | Bin 2050 -> 1817 bytes Piece.class | Bin 1092 -> 1235 bytes Piece.java | 8 ++---- Rook.class | Bin 0 -> 1361 bytes Rook.java | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 Bishop.java create mode 100644 Rook.class create mode 100644 Rook.java diff --git a/Bishop.java b/Bishop.java new file mode 100644 index 0000000..f78ce0c --- /dev/null +++ b/Bishop.java @@ -0,0 +1,72 @@ +import java.util.*; +import javax.swing.ImageIcon; + +public class Bishop extends Piece { + boolean hasMoved; + + public Bishop(int x, int y, String color) { + super(x, y, color, new ImageIcon("sprites/" + color + "/bishop.png").getImage()); + hasMoved = false; + } + + public ArrayList getLegalMoves(Board board) { + ArrayList positions = new ArrayList(); + + // check left + for (int i = pos.x - 1; i >= 0; i--) { + Position test = new Position(i, pos.y); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + + // check right + for (int i = pos.x + 1; i <= 7; i++) { + Position test = new Position(i, pos.y); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + + // check up + for (int i = pos.y + 1; i <= 7; i++) { + Position test = new Position(pos.x, i); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + + // check down + for (int i = pos.y - 1; i >= 0; i--) { + Position test = new Position(pos.x, i); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + return positions; + } +} diff --git a/Board.class b/Board.class index 14395b1f7ea29474a5f885a4442ecf0064edc88c..6328222abe679d29c1a9f0e72784e6420d8a3668 100644 GIT binary patch delta 345 zcmYL_F-rqM5QX1ta&EF7iUi>-f&_y}cB7Y^MvF9B*+fh&Hb*%0QW!}NE&UPuBT{Ig z5K>s!3WA+~!`@0AFG|?q!G1IE?Xd6iE~j3U=%0u;Iduoq_AyWGTt^}r5|30et47kN5k;yBJPbO8uoZIp*UsoCf1pJ2(PgvA&De>E+WADX0s!qBxWt(lSv*;1ZiX|vwv%N_umJA zHPl%hi1Gn3*qIG6YC`Yl4G>JFJ|OFPoYdv+x7mGB%9JKOg4&lT=Ya# SnOLO!ahkuJwZPd4@$NUPPAD<} diff --git a/Board.java b/Board.java index b95f324..4355039 100644 --- a/Board.java +++ b/Board.java @@ -6,10 +6,10 @@ public class Board { public Board() { board = new Piece[8][8]; for (int i = 0; i <= 7; i++) { - board[i][2] = new Pawn(i + 1, 2, "Black"); + board[i][1] = new Pawn(i, 1, "Black"); } for (int i = 0; i <= 7; i++) { - board[i][7] = new Pawn(i + 1, 7, "White"); + board[i][6] = new Pawn(i, 6, "White"); } } diff --git a/Knight.class b/Knight.class index 5ee2504717e01cb273e75de76eee66f818604658..07712eeac1a5590877a9297f06274e870101bc49 100644 GIT binary patch delta 556 zcmYL_%TE(g6vltI)0x)E6qU9>O^OC3X-i`hO+cx|w<5N--~)=Uj%A=Fq&2q6l8yht zY?PI8)1^uX7)fyN)}?Xj&OgAIh@Pn?F77$s{qA=j_xotQ37MbvKI{VLvEP~B)SAgj zPFsvKrZDQQ;$x>_65)(RjtPZkFDxjciTtwt%+9RXjipTS(Xvx*XOr_@={ZX}T~Gv< zoOY@1R2@Y)kuNn{^>)44$R_h$GHY^xOBR>8qOhvXmFAOz-LBT0mZ>mB?^U|r)vCMb zYpYxC7vG_tJ0`Qt1t?qS%)6TQ*?(U#>}IrKBfv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zI zZOjI;VJ5g}a*1hyUi6%*D+uTFc4oC)Do=zNV8&#YIaMurYhG0lvF|&NoUt`$y)ric zpt`zVQLqEd7>sbmT45(RqmJW+x14P;*}zUVxv+~E_d~{;q}Ba$i&z6I^=~RW=dZgpKatY3?w#z|OryPi?9EP=j<2mt5&HLme6`B^UZ) zwH9_RwWXRE;CDl()C|Es_OPF{YOlv24;f;UgM3wO{=u*a5)~Fl#4>SF=BRkWG4YfW z;tiJgqUI{A7$WH3*$gq#W}{6}w3*{(N9C3phFm9FV3ETpDZw4JZc|igLq#RZREYip D5LmRX diff --git a/Piece.class b/Piece.class index 472ecfccb1b85b1784ca5fba7f26891c36bfa1c4..8f66b7143f5cec9feecafab0ebfe05d043c1e4c7 100644 GIT binary patch delta 330 zcmX@Yaha3r)W2Q(7#J8F8N4@gy=HXeVlZPcXJ@eBVX$PdVq_4=N-Rs%&q>Tn*AFf! z%FIh=WME4zEKSTQW@Hf6@IlD>CuOB3mso2?ZT`xr$SB2=oS&0lIyfYj5~t|$Yh|r3REwT))odKZ6MypV7dmbn+>RnfkBFa Nk%Pe#$Y5gd0sza(HQoRK delta 186 zcmcc2d4z-O)W2Q(7#J8F8JstAy=L5O#-zwNxtLki(3HW9fsw%+D8&ZWuW!Y^QY{4QjEC!+0Kvi5oGZ=vSZ0OT<;AoPeba4?8LUEu(faRkaUF*pGLejFBL diff --git a/Piece.java b/Piece.java index 4465faf..6b99592 100644 --- a/Piece.java +++ b/Piece.java @@ -1,8 +1,7 @@ import java.awt.*; import java.util.*; -public class Piece { - ArrayList legalMoves; +public abstract class Piece { Position pos; Image sprite; String color; @@ -17,10 +16,7 @@ public class Piece { g.drawImage(sprite, pos.x * 40, pos.y * 40, null); } - public ArrayList getLegalMoves(Board board) { - System.out.println("parent method not overriden"); - return null; - } + public abstract ArrayList getLegalMoves(Board board); public boolean colorMatches(Piece p) { return this.color.equals(p.color); diff --git a/Rook.class b/Rook.class new file mode 100644 index 0000000000000000000000000000000000000000..639094ab2d8df81100696dc2a08531a85c9cecb6 GIT binary patch literal 1361 zcmaJ>*-{fh6g?dRlZ?Y+1W`cTSds|DeG8%xM5BpX#=;VxnxrcX4AXI@!}8{XAED(3 z@Tye;RZ!&z_(xi$czXf`2=Xw!+`jjobGP~NXX877QREGT7}{p}0$)n`i?&-%W#@TW zWQ)>`kw(};JsKF==lPt-NVmw#>CC)hRxSmhXilRyXf9}l?pazxG?-Cbr}YNi-orqc_EfU7 zYj6|n&EN*=fOQyaIJS=FWZf!SlY_C2HFSM~5n4ewyow8714lP$jRodWw8KOfj$sHE zZjrnnp)Dj4HqgeHK~qOd+ZH|SN<#XLc-+PvVx`$Uqg}J<+C<-*b;R?@Z@BagsgX0E z5&clNwX*ed;0wKnprM;IQ#2z&Bs$O getLegalMoves(Board board) { + ArrayList positions = new ArrayList(); + + // check left + for (int i = pos.x - 1; i >= 0; i--) { + Position test = new Position(i, pos.y); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + + // check right + for (int i = pos.x + 1; i <= 7; i++) { + Position test = new Position(i, pos.y); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + + // check up + for (int i = pos.y + 1; i <= 7; i++) { + Position test = new Position(pos.x, i); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + + // check down + for (int i = pos.y - 1; i >= 0; i--) { + Position test = new Position(pos.x, i); + if (board.isOpen(test)) { + positions.add(test); + continue; + } else if (board.getPiece(test).colorMatches(this)) { + break; + } else { + positions.add(test); + break; + } + } + return positions; + } +}