Java 2D Arrays & Tic Tac Toe and more banner

Java 2D Arrays & Tic Tac Toe and more

8 devlogs
14h 56m 18s

This is my collection of games and simulations on Java 2D Arrays, including Tic Tac Toe, multiplying, summing, mirroring, randomizing, and more with fun with matrices!

This project uses AI

I converted the java (which I spend 10 hours making) to js using an ai model that I programmatically called. I made all of the java being converted myself, and I custom coded the converter logic in python (no ai code help anywhere all of the ai-made-code was generated was by my own code), and I needed to organize the outputs and manually enter them and fix them when the ai messed up. None of the app ideas or creative power or source code was by the ai. So by no means was this gemini’s project, and I did not expect this in the first place - this was the last resort because there cheerpj was not working - I literally had no other option (I am not a fronted person)

Demo Repository

Loading README...

shreemahor

Shipped this project!

Hours: 15.67
Cookies: 🍪 284
Multiplier: 18.14 cookies/hr

I mastered Java, and a little bit of html, js, and python. The hardest part was at the start when handling rows and columns but after testing a lot it worked. Also, please don’t have any prejudice against my project for using my coded py file with an ai model to convert my java into js because I worked a lot on it and the java by myself and browser java (cheerpj) I had no license, but this was very fun 🍵☕

shreemahor

I added the final touches and finally got it onto Github.

  1. Committing it on repo
  • Tried Dev Editor but copy pasting did not work and I thought that I could escape that by making a zip then opening that inside the dev editor but that also did not work
  • Moved irrelevent stuff inside other
  • No longer using the .jars they are just there just in case I give cheerpj a hundredth chance
  1. Organizing files
  • Weird naming issues and errors with relative imports and how many ’.’s and ’/’s to use. I just tried many combinations of ‘../../’ and ‘..’ or just ‘.’ for imports and references until it worked but that was a serious problem because I would have to go alll the way back to EACH file that went and used it before and change it
  • Tic Tac Toe was missing a button to go back home so you were just stuck at the board but I fixed that
  • Converter messed up many times like on random array there were just strange blank white box divs and I don’t know what it was trying to do but I needed to go in and clean what it got wrong so that was annoying
  1. Art Design
  • Lots of emojis
  • I can hit command v on my laptop and quickly paste them in and for the icons for the tic tac toe difficulties, I used emoji kitchen to make those images
  • For the card thumbnails on index.html it was 2 emojis a card
  • I used lots of symbols for matrices but honestly I should have spent more time on code and less time on this
  1. Other
  • I went in and went inside each card/app and went out but it turns out I forgot to renovate latin square so I had to go back for it
  • I am sure the website is working fine now
Attachment
Attachment
Attachment
Attachment
0
shreemahor

Have to make the index.html and links work out right. I finished converting everything but still need to polish it and make the inks work out. I keep having a problem where the main files are inside subdirectories so I dont know how to get the index.html which is all the way in the root, but I will figure that out on github pages. Right now I also got a home page but need to fully populate it with all of the apps. I also have a ‘simple java 2d array’ where its just a simple page that says what they are. Surprisingly the random array was the hardest to convert because values kept swithing to “NaN” for some reason and everything was in its own line, but I decided just reran the converter and worked with what I got. The way the apps work is that each one is like a card and I just copy paste the format over and over. I still haven’t faced the github specific problems that might happen so I really need to do a commit.

Attachment
0
shreemahor

I just continued making more files like sum& mirroring multiplying rows columns diagonals and more. The converter did really bad for the random array so I am running it through again. One time I accidently deleted the core instructions when I meant to just delete the special instructions I gave it so I lost some time just fixing that and recalibrating it. Usually styles say similar because I use the same exact model and I use the same exact prompt that says ’add these js snippets on the back: {…}”. The neon green div is the closest you can get to java console on the browser. It updates it with the same stuff I coded in Java. right now I still need to get this on Github so I will do that.

Attachment
0
shreemahor

Every time after the java is converted, I need to fix it up and put it in places (and adjust the converter for each convert). I combined my java files for summing matrices and mirroring them into one file. Also each time that I put a new file onto my converter I always add some app-specific lines like ‘this has 2 matrices and the user needs to have a table’ or there is this problem or something like that to help the AI model in the converter. The JDK sometimes gives me problems because I just refactor my java code a lot and don’t specifically manage my packages, but I just use that for testing anyways. I like how each file is consistent and simple with the html design and it remains true to the original java.

Attachment
0
shreemahor

I spent a lot of time just trying to fix this annoying ValueError. Once I figured out what it was I realized how simple the fix was. In python variables are passed in strings with {} but js and java also use {} so the doc string had lots of curly brackets. And the converter thought that the js’s {}s were variables. I thought it was my format or my model issue but it wasn’t. I also organized the converter outputs and actually tested the HTML live with Live Server. I needed to manually move all of the code that was created and create a .html .js and .java file in each subfolder and wire them together (.java was just for testing) but everything worked out in the end.

Attachment
0
shreemahor

I have found a workaround for cheerpj and that is converting java to js. I am going to programmatically use an ai model to covert the java into js then make a specific html file for that js. This is NOT asking chatgpt to just generate a js games. All of the ideas and logic I hand coded myself (10 hours) and I am programmatically using a specific model with specific prompts and logic in a converter mechanism I coded myself. It’s basically java => converter model => js then js => converter model => html. Then organizing what it gives me. First I got some Value Errors because I did not know the properties of the prompt template but then I figured out that you input the prompt as a python dict {“key”: “value”} instead of an f string so it worked out.

Attachment
0
shreemahor

I tried to get java on the browser directly - jars and cheepj repeatedly without any success. the jar format is just the way cheerpj, a framework for java directly on the browser, needs to work.
I tried:

  1. Compiling the jar in java 8 instead of 21 to see if cheerpj needs older versions
  2. Putting each class into its separate folder and compiling, but nothing changed
  3. jar command but it says that jar can’t be recognized
    The chrome browser console keeps telling me ‘error at line 1920’ where str output blocks are turned into the browser that I learned when I looked at the cheerpj code but that makes me think that Scanner is making problems so I am going to try workarounds to cheerpj. Also before it gave me a 404 but I double checked spelling and location and it was good.
Attachment
0
shreemahor

I didn’t initially plan on submitting this project for flavortown, so thats why I have gone so long without writing a devlog, but to compensate for that, this devlog is extra long.

  1. Full list of files that I have made:
  • Summing Diagonals
  • Multiplying Matrices (2D Arrays)
  • Finding the Largest Row & Column
  • Latin Square
  • Mirroring Matrix
  • 2D Arrays
  • Random 2D Arrays
  • Sum of 2D Arrays
  • Tic Tac Toe
    Problems fixed:
  • in tic tac toe game needs to stop once its a draw/win but those just accept the board as a parameter and the board is initially blank in the main method, so I think that it was always using an unupdated board, but the fix for this was to have a new method that returns true if the game continues and false if the its a draw/win
  • Mirrored Matrix and generally its hard to get columns columns needs to be equal to rows but columns is nested inside each row so you would either iterate too much or too little the solution was using how columns=rows to treat both similarly and use a for each loop or just one for loop
  • every time you needed to print one 2d array, you need 2 for loops and 2 new loop controls - fix just to create a method that does it
  • multiply matrix formula is super hard so the only way I could get it was just trial and error but at the end it was ‘product[i][j] += mat2[p][j] * mat1[i][p];’
  • using a place variable outside and a break; instead of multiple for loops even though it was slightly more hard to understand when the break would trigger as to the easier 3 or more for loops
  • indenting matrix so you could see structure better was helpful
  1. Future
    Have to find some way to get the Java on a website
Attachment
Attachment
Attachment
Attachment
Attachment
0