From 48ff5b4fce43e55b88dc4acd77533fcbed01deae Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 20:49:05 +0100 Subject: [PATCH 1/9] Add some Implementation Methode to AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 64 +++++++++++++++++++++++++ team.md | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 1e9c686..cb1b9a4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -1,6 +1,70 @@ package BattleShip; + import javax.swing.*; +import javax.swing.border.Border; +import java.awt.*; +import java.util.ArrayList; +import java.util.*; public class AIGridGUI extends JPanel { + ArrayList buttons = new ArrayList(); + ArrayList allShips = new ArrayList(); + // public ArrayList listeners = new ArrayList(); + + int[] testLocations; + int numOfGuesses = 0; + public String text; + int rows; + int columns; + boolean endGame = false; + boolean[] cellsGuessed; + boolean[] cellsHit; + boolean[] cellsKilled; + boolean randomGuess = true; + int f; // it is the first + Color Red = new Color(100, 0, 0); // + Border loweredBevel = BorderFactory.createLoweredBevelBorder(); + Border defaultBorder; + Ship shipToPlace; + boolean vertical = false; + boolean clear; + boolean shipsPlaced = false; + Ship destroyer = new Ship(2, "destroyer"); + Ship cruiser = new Ship(3, "cruiser"); + Ship submarine = new Ship(3, "submarine"); + Ship battleship = new Ship(4, "battleship"); + Ship aircraftCarrier = new Ship(5, "aircraft carrier"); + ArrayList directions = new ArrayList(); + Direction up = new Direction(); + Direction down = new Direction(); + Direction right = new Direction(); + Direction left = new Direction(); + + public AIGridGUI(int r, int c) { + + rows = r; + columns = c; + + //Create arrays to keep track of which cells have been guessed, hit, and killed/sunk. + + cellsGuessed = new boolean[(rows * columns)]; + cellsHit = new boolean[(rows * columns)]; + cellsKilled = new boolean[(rows * columns)]; + for(int i = 0; i < (rows * columns); i++) { + cellsGuessed[i] = false; + cellsHit[i] = false; + cellsKilled[i] = false; + } + + //Add all ships to an ArrayList to allow for cycling through all ships. + + allShips.add(destroyer); + allShips.add(cruiser); + allShips.add(submarine); + allShips.add(battleship); + allShips.add(aircraftCarrier); + + + } } diff --git a/team.md b/team.md index 969138d..5690043 100644 --- a/team.md +++ b/team.md @@ -1,4 +1,4 @@ - Berkan Sarp, fdai4616 - Justin Senn, fdai7107 - Eren Esen, fdai4581 -- \ No newline at end of file +- Brice Tchoumi, fdai6138 \ No newline at end of file From b9530e5089495f45d15d65bf99fd46333de090e9 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 20:49:51 +0100 Subject: [PATCH 2/9] Add some Implementation Methode to AIGridGUI --- target/classes/BattleShip/AIGridGUI.class | Bin 0 -> 2331 bytes target/classes/BattleShip/BSButton.class | Bin 0 -> 785 bytes target/classes/BattleShip/BShip.class | Bin 0 -> 262 bytes target/classes/BattleShip/Direction.class | Bin 0 -> 678 bytes target/classes/BattleShip/Ship.class | Bin 0 -> 873 bytes target/classes/Snake/AppleView.class | Bin 0 -> 971 bytes target/classes/Snake/GameView.class | Bin 0 -> 1549 bytes target/classes/Snake/Window.class | Bin 0 -> 2033 bytes 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 target/classes/BattleShip/AIGridGUI.class create mode 100644 target/classes/BattleShip/BSButton.class create mode 100644 target/classes/BattleShip/BShip.class create mode 100644 target/classes/BattleShip/Direction.class create mode 100644 target/classes/BattleShip/Ship.class create mode 100644 target/classes/Snake/AppleView.class create mode 100644 target/classes/Snake/GameView.class create mode 100644 target/classes/Snake/Window.class diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class new file mode 100644 index 0000000000000000000000000000000000000000..a21b7becd014c42309c30f774136d8ffce22a165 GIT binary patch literal 2331 zcmah~Npl-T6#m+hEk*9cj+{NQvqEfT5o94DO6*up>?n3(6FW9e*hVvLdy=unj7E0M z9tiu+kt0|Rv3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jVr4`lDQEA~A8{5Aa7B z@021BanWh+^xSj4d;9hM@d@AzhbjUHMxba2Aq)D0mlvpwMVm3n*Hq4iA5YB;tqZ82m>w&qk)T9q#A8WPxG z(E2XFX*oSZaGA!M3`)bfF&PpqZkt!5yRPY88(oWTQc`Di442E=zf{D4Q%ZI|Wy(?| zm!T;x79x~Vv)rL1i$3<3KhlsyAe$NsLu5+x{@xUx2_;LDMRB@R{-b74+s?@Cnde-N z5}zU-%cY}88wt=)kq@nfPRI?@83L1kht4EbC!}EXR`quAgDh1HIplqp8YyK`STBqbUv`L5p5{5^CMw^7^w=aeS{=5q?R!Ad#0Pko-!J15Z`_0k7_VP5=M^ literal 0 HcmV?d00001 diff --git a/target/classes/BattleShip/BShip.class b/target/classes/BattleShip/BShip.class new file mode 100644 index 0000000000000000000000000000000000000000..5809f278ff7e8939575c60289d36030ff7ab2d11 GIT binary patch literal 262 zcmZ9GI}XAy5JYG5ArQXe26R9{4#1}Xi3&jhqIZHt9EAi0!@a1GC^!IzLaZYyZ0UJt z*1MYb=lKFKMaPE)+k?}9iwdEWh?@vfksX6gn8-*IDif6{JtNrt!QMlaKh1^Ksociu z9Lx;~<fZLVKk$xxSu4S?olZveRAVkx2KVP)7euN5|@7djE^Y1b>@fi%2e&nfA-| uBNGZec%0Q7;>&57HC92X0eAQS-Py31T>Zr20c6E@pIxCqi_+q-j!s4^6xk&yb>JK5II^I9~zx3cp|ceVoM8?C%0^5!D^>VXE(2MCg zL4}Tt!;{&hA0}^ueq?B-gCOb!iPYy+(NZHxeWlKte0C68Vl3beLv><=R2t3eJvk^J zbc}f8Oj{r$uU>P+@Z1#6$T67CVihI=`K}5E<2S+ONTGUEJFME`3=8S2lu=aJ&JWUk6t=g75zYzvqxzcHMtBhiiS%hB4tPeMZK& nw0CnD+O%=4Y`$cVzU^ZRb=D65Yf)bf_kffnu93T8#%cZmSa^Wb literal 0 HcmV?d00001 diff --git a/target/classes/Snake/AppleView.class b/target/classes/Snake/AppleView.class new file mode 100644 index 0000000000000000000000000000000000000000..dde14d22361212c9c69b30b0015d13983ba24d70 GIT binary patch literal 971 zcmZ8gYi|-k6g>mmE{`dXMX9x|?*|VHzF*W7YCg^|m#f$F%_tU-(2?XwA zTQ#1iW<&voWpqrZ6Lo223A)biyRlQ#1J0{ui>;!e?F5t z3!wOyv7%#@;}R~<>fLfI$E81c_o{Y^dEBqWa23~dT<5rfn+)kd*c;dEcV&A(!ijqV zGE3~w=bK9AZH^rBq`f1&k7L(rs$Jx`bJE^ZOeKyo?h@oDX<6Hcrp2I>d&)l@_er(y zTFo_wX3HWMv>Yu_+H&@(N;ae|-X45u3HQCfZYWc%rs+ymPnw$7m83h}ICBOS-^ZQc z9OAYZPAhGnXc@9I=AM{PQ6gA}Au}~TSYwFoItOlByp~FGA~^GsGL!y#f$kf_J&K09 z9CQf{b<~u@)StrxiVvy!K;I$Ci-lvb!f)t%;qWn{N8p9!BN*RlDTGH94QLb-6q5v( zLYCrV>SXSBeUDgj?Sz8(qIB1cjlxBdkq16XXHt>grg*8dhg`O95|*9__}M Kca!#p@bW*~Zn?n# literal 0 HcmV?d00001 diff --git a/target/classes/Snake/GameView.class b/target/classes/Snake/GameView.class new file mode 100644 index 0000000000000000000000000000000000000000..323b53df5257f47cb346b60d1854cab8906b5841 GIT binary patch literal 1549 zcmZ8hT~`}b6x}x&7)XZl(GqH*m3}BmXi4$28j3=&F*Q&$m}L+X?^x5 z_~I|{#h1Elu)3DZXMc!4!sSx;olJ(*m9=ipoO|v*`<%1y{o|isegkkDy9vY)H(^*9 zz@Wgy1Nl%s%C(Mdr;)q6DIL`m7+kU)+g}!lr!!R(Lt$7>9{ag9`%pP8+jSB!k|c$q05veK5oWH;sW(Rm%2wva(qV5s5QVG~42<6O6J0}JfAtdquMNTVq^mwUSp zRL#$4cJ%OWT3Ey@EcZy-j$d#Ok6cGNzCfyvdC`+c`*y7rv~m`&S$G|9Fsbb;Px`t! zsdT1~V=46KlemSqOuTI&kEPz+gED#{0_MJK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 Feb 2023 21:09:31 +0100 Subject: [PATCH 3/9] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index cb1b9a4..b017b6c 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -64,7 +64,25 @@ public class AIGridGUI extends JPanel { allShips.add(battleship); allShips.add(aircraftCarrier); + //Add all directions to an ArrayList to allow for comparing and sorting directions. + directions.add(up); + directions.add(down); + directions.add(right); + directions.add(left); + //Make grid that consists of r rows and c columns of buttons. + + GridLayout g = new GridLayout(rows,columns); + this.setLayout(g); + + for(int i = 0; i < (rows * columns); i++) { + BSButton b = new BSButton(); + b.setGridLocation(i); + buttons.add(b); + this.add(b); + } + + defaultBorder = buttons.get(0).getBorder(); } } From 29f7ebc26f765da449aed07adc2854c95d453f44 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:25:53 +0100 Subject: [PATCH 4/9] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 61 ++++++++++++++++++++++ target/classes/BattleShip/AIGridGUI.class | Bin 2331 -> 2901 bytes 2 files changed, 61 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index b017b6c..0bfc9f9 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -85,4 +85,65 @@ public class AIGridGUI extends JPanel { defaultBorder = buttons.get(0).getBorder(); } + public void autoPlaceShips() { + + //If ships are to be placed automatically, randomly place each ship. + + for(Ship s : allShips) { + int shipLength = s.getLength(); + int clearSpace = 0; + testLocations = new int[shipLength]; + + //Randomly select starting position to place ship and check if sufficient space to place ship. + + while(clearSpace < shipLength) { + + //Randomly choose whether to place ship vertically or horizontally and choose location of ship. + + boolean vert = new Random().nextBoolean(); + int x; + int y; + + if(vert) { + + x = (int) (Math.random() * (columns)); + y = (int) (Math.random() * (rows - shipLength)); + for(int i = 0; i < shipLength; i++) { + testLocations[i] = x + (columns*(y+i)); + } + } else { + x = (int) (Math.random() * (columns - shipLength)); + y = (int) (Math.random() * (rows)); + for(int i = 0; i < shipLength; i++) { + testLocations[i] = x + i + (columns*y); + } + } + + //Check if the location is clear. + + clearSpace = 0; + for(int i = 0; i < shipLength; i++) { + if(buttons.get(testLocations[i]).getCellContents() == null) { + clearSpace++; + } + } + } + + //Set the contents of the chosen cells to contain the ship. + + for(int i = 0; i < shipLength; i++) { + buttons.get(testLocations[i]).setCellContents(s); + } + + testLocations = null; + } + + // + + + + text = "Ready to start the game."; + shipsPlaced = true; + } + } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index a21b7becd014c42309c30f774136d8ffce22a165..e603c494a8fd0bf61d7e252dc389dea1f4b294da 100644 GIT binary patch delta 858 zcmZuuTTc^F5dMbUZDm(( zaJ?g5Kn2AcQA?D>7#~c~#24d>FZvtwjYM&}Mc~1loSE;;eCL}va|Uw0=E@)cymdiy2W#Z{gv}xl|df4<8&X=DL%5dVGg7dgQ5JI|1aIspN z*`|d<-l|}$-e?y4QjPR0xQI3UDkl1kNRuAPF>!-7=s+!LUA&Il^kVvBM6|8Y?U%(LC4=A=aFY1evfl}&3 z8TF!^ECgs6l{AVfdW~v&kDWAy8v24-`o^&zsH2~#$1n?&^S{r)gL^zVftf3C9}ghW z7&h85F*OB@U^F!`Mh}@sHhRP;gX>gd4Bp4w&l6^>f;hu^q7zv}%$r8RZ*)5mqiJm5 Li%*%8foFdKR1Vu@ delta 301 zcmcaAHd~16)W2Q(7#J9A876Mz5@DI_%Q}~jHzhSKu{5W|DZeNswP^ASRu48-4Np(a zu*rICCX?&fG$tQnv)8Qz>SAK30+K=u{0xi?5Pmg~U&BxfBpDb)8N`4jBSRfS{bW6M zTf+u0pMgP@K@BXg&tL$i8=-U)g9Dgv%pe7(n_h=m2uGfNK6TXfSjF?PUh3X6Rz*2AK?G r^#H{f!K_{&i;1BRC@jRl^dG2!g`I($kr62Qi$NWzrXMK7#4rH>@Axw# From dd5ac1e70856d41bca258827c7d86c6f4428cf44 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:30:40 +0100 Subject: [PATCH 5/9] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 0bfc9f9..fc1e823 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -138,9 +138,15 @@ public class AIGridGUI extends JPanel { testLocations = null; } - // - + //Mark all cells containing a ship and disable all cells in the grid. + for (BSButton bsb : buttons) { + if(bsb.getCellContents() != null) { + bsb.setBackground(Color.blue); + bsb.setBorder(loweredBevel); + } + bsb.setEnabled(false); + } text = "Ready to start the game."; shipsPlaced = true; From 0beb11e56f380a2d8f417fd321536ee3e6fb1d65 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:34:55 +0100 Subject: [PATCH 6/9] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 4 ++++ target/classes/Snake/Controller.class | Bin 0 -> 267 bytes target/classes/Snake/TextView$AnchorType.class | Bin 0 -> 1148 bytes target/classes/Snake/TextView.class | Bin 0 -> 1969 bytes 4 files changed, 4 insertions(+) create mode 100644 target/classes/Snake/Controller.class create mode 100644 target/classes/Snake/TextView$AnchorType.class create mode 100644 target/classes/Snake/TextView.class diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index fc1e823..ea4014d 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -152,4 +152,8 @@ public class AIGridGUI extends JPanel { shipsPlaced = true; } + public boolean getEndGame() { + + return endGame; + } } diff --git a/target/classes/Snake/Controller.class b/target/classes/Snake/Controller.class new file mode 100644 index 0000000000000000000000000000000000000000..5bee98bb578a0da944c4bb962b9e4ed1bd74d766 GIT binary patch literal 267 zcmZ8b%WlFj5S-0}Ku8wyu`X z%1`Hif6RR{OptJ3e~2$fW*jgpIu69MFVH6o0a8Y910jZtS@({)J}@IZG6u+h0cv12 Al>h($ literal 0 HcmV?d00001 diff --git a/target/classes/Snake/TextView$AnchorType.class b/target/classes/Snake/TextView$AnchorType.class new file mode 100644 index 0000000000000000000000000000000000000000..fe89e53a26ef30de777f97360bbc5aee8ce0ade5 GIT binary patch literal 1148 zcmaJ<|4$NO9DZInIJnLvG7Us4vjk1a(ySn-W4hdKx^>3p`st)sJUd_7aajFVg z&7b?DTA%mz9555u`0#n&=kxvf^Y_PZ0IyKe5n;&K!ui09+x&A-b@`{sRZ-h-_}gDT z@+25E6EVceT6`~H7`3ismn1!5A}Q(d3Ks$QC3MY%DWTXKx4s`pZyy_&8aH*MObp=`<*9iM!5N0~1?#{$a*CcK>cy?y16~VC21amON5(`Jqg1Iw zSQD*7DtY91ExxtKu$b?Pu6RzfS?U7pz;{Kx)LlU)Q2ED9jN=Z?SayXQEHeyurwSuC z3e^N+22DGbKr#VS{(WHLA*STus*NVYc)rkYbSiSe)GCelH1(k63clGo+~xkZv+EI3 z{7>~lpLH^%twzo9s*dl<3}G5gIER!ieR&CV{9xauW|OvC7f#Ufi5JZms&wvh%?p<> z+Z8BRRqoTma*4sP8!f-a*IhZoz=ite8_ht+bGl-$<`~QkA-J!O#;Gr( zBiWUCTJs30TU*IU;R0kyk;;+`fmBwCj~Fq+^Oz!jfxHQ_@?*3y@EteKkp4;@!!-TI z)tgTIEM`Lf0wM}E(ro$^!)IWUAL-#gBE&prVHR`hos>f?S#cgw`U3j&Ozs4^Z|b?b zTqj&dQMQi9iZh=wq>REwiqHrJM&iG~cA{-W?H#QR-QJ0{X~~zTNZ<+8KA(C$44(T* zvFW?f6WlvSR5=rxa&+a~k15AE#pE#tWUIZK(ZbfAVu9WwSj01Bm+*qDls>}}Uan;R E0Zqi};Q#;t literal 0 HcmV?d00001 diff --git a/target/classes/Snake/TextView.class b/target/classes/Snake/TextView.class new file mode 100644 index 0000000000000000000000000000000000000000..f8a960d0e1d2be1b4cfe6bcd09e8098c9c77ed08 GIT binary patch literal 1969 zcmZ`)TU#1e6kP`gMsPG<(5OVKsahDU*5)3RBsDRTqDiC0*4{G00F%(c4<<4Gl>UMA zx%ndbzC82?^!N0kPx-pe83f|xfjPH**4}&VbvFNe{O~t`6_g_gpi75lAc&Aa- z?S>7E;G%&3%Beeh6K$3+!h?~duvtK+ptNR+!&1~+8K15 z5I>HD4%0vq^SsysQ|vOM*ZgIq)q;UVX(A3ISi;vjt{AwAYXZ^Moep4uFk@J^ol@E7 zKO=A5FmMyM1bXVKm^)6vD+>&tQRW1Fjv-}WS!N!5DsjR{;x{J5o9Kl z$mz(oBz&LtmJ-738P@Fr_{vS>D8$ujfl|1TbzFP% z9V$-An_)s98*7p?fsqbsk7cQBdy1X19BFgXp&jNUN&-Xe!xn@<@0MrfUu;?P z)t9xrz2?aG*L&PV7NjPrvrW6sM<976Z$`#-?b>R^s@H8UBkjkCX+E=V2z(2TGxi8} zs(|bQYUC?dBVQrM5bc84;CGX&N4(L+vD-|}YwsccQkIYTm2D10&=JKG&Zc}je21r8 z@rLpv)J%E`C|rpyaSyoGIL6HP(9Pr#40HYn{pQ3GqUKwS9$~WWYMeoVL24L&q6AIwm(0$Dbg^l@JD>B7Jdld zlR}meIqaOmiZO+gShK{MI|u6r#wD?S#O^6964SwhAD2n2hv*-$k_}96aNhq8U!?u<%lQVr3Ra$7*SMY}`EM{ZG0(Zt!1Z9Ikp2^+{>kk( z=xd!6(#f}2X<#)eO(%x61|G`1yCCJUfF6FAD32?UoivJTn86M1-(;V=g>~F!C6<}< z3T)g_`CMhB26^}uzmf4M`DWK9-V8e;o3pBNu~mg4p21?4d-T(Xu8&CTSP~-o9|m|Q X&)onD#0Ky2uL?!ZB5D>u>F(J7!TO7m literal 0 HcmV?d00001 From 6a8f0f3c1d8d02ab738e69a0e4502f5a098251ec Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:51:19 +0100 Subject: [PATCH 7/9] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 29 ++++++++++++++++++++++ target/classes/BattleShip/AIGridGUI.class | Bin 2901 -> 4913 bytes 2 files changed, 29 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index ea4014d..dbefd40 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -156,4 +156,33 @@ public class AIGridGUI extends JPanel { return endGame; } + + public void go() { + //Play a turn by making a guess at a cell. + + int guessLocation = 0; + boolean gameOver = true; + numOfGuesses++; + BSButton b = null; + Ship s = null; + boolean killed = false; + boolean isClear = false; + + if(randomGuess) { + //Find out the maximum ship length of the surviving ships. + int minClearSpace = 0; + for(Ship sh : allShips) { + if(!sh.isKilled() && sh.getLength() > minClearSpace) { + minClearSpace = sh.getLength(); + } + } + + //Create an array of all possible cells and shuffle the order of the cells. Potential guesses are drawn from this array. + + int[] guesses = new int[(rows * columns)]; + for(int i = 0; i < rows * columns; i++) { + guesses[i] = i; + } + } + } } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index e603c494a8fd0bf61d7e252dc389dea1f4b294da..9814b983104401ef6f2a20478b7940a270f0e162 100644 GIT binary patch delta 2266 zcmZuy32;+Y6g@9Xf0F*Pr&7vNhJk5IX?4Uh!{T78BOp))97aHp-}aM~rb$hHSsXEA zWkAsZHOh`46biC04P_AvA|SW`iaW|CqM#xu0+z<}ep+P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Cl;cOoU7bQ6)q|@?Xc!L-Ok%9%h4jm;pR%gbSFi9K?*S( zSK=T(VZaLBsERbKB=f7#0@Y}Z)g)#OQuv^yVLhqZfIMu(qu4}tw@@EZ%5*#BSBvL3 zzkpq49m-kDJbGOtnNA8g)nwgC{|Wfh)J`e?V_nDEFeSsHG#1Q)=W&DEeC(;*o0O4- zX*^{a%P=;ggrx#w0gYi|m<}X`82A|&86f-_K>kdI zSwND3L6kuZNHQ|aW|%Wsip!R9?&JtAdBJ%M4j@SeV+JWOJ%4fsmn}O)_kzi1xD>e= zfqGaOYJud!%|EzUm>3sL{>yXPe=$(G2Ln69e+CVPB|xK@84oc?Ff3(Q#=y$Bn!yw- z#sakOGsAL*6(FO5td&4@j9}I(Ad87{F+%{uYKAoo%nWNMi}NY7uLCM$VptCVQKmpm From 4c5bbea894e20904081f20dc3a306e22cedc0ab5 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:57:43 +0100 Subject: [PATCH 8/9] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index dbefd40..5afe8d4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -183,6 +183,13 @@ public class AIGridGUI extends JPanel { for(int i = 0; i < rows * columns; i++) { guesses[i] = i; } + Random rand = new Random(); + for(int i = 0; i < guesses.length; i++) { + int randInt = rand.nextInt(guesses.length); + int randGuess = guesses[randInt]; + guesses[randInt] = guesses[i]; + guesses[i] = randGuess; + } } } } From ba218b5315ea6b009a1be236f794db48c05e51ba Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 22:19:42 +0100 Subject: [PATCH 9/9] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 5afe8d4..3f059a4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -156,7 +156,6 @@ public class AIGridGUI extends JPanel { return endGame; } - public void go() { //Play a turn by making a guess at a cell. @@ -190,6 +189,36 @@ public class AIGridGUI extends JPanel { guesses[randInt] = guesses[i]; guesses[i] = randGuess; } + + int numCellsTried = 0; + + //Test potential guesses and mark clear if criteria met. + while(!isClear && numCellsTried < guesses.length) { + guessLocation = guesses[numCellsTried]; + numCellsTried++; + + //If the cell has not already been guessed, test whether there are enough clear spaces in at least one direction. + if(!cellsGuessed[guessLocation]) { + + int u = guessLocation; + int upCount = -1; + while(u >= 0 && !cellsHit[u]) { + u = moveUp(u); + upCount++; + } + } + } + } + } + + //Return the location of a cell one space in the given direction, or return -1 if out of bounds. + + public int moveUp(int u) { + int dirUp = u - columns; + if(dirUp < 0) { + return -1; + } else { + return dirUp; } } }