Inspiration

Honestly it started as a joke. "Playing 3D chess" is a term for when you take strategy to an extreme and seriously out-think a problem or opponent: a great compliment. However, "Playing 4D chess" turns that around and starts being used ironically as a way of saying you are out-thinking yourself, and your idea of strategy is so complex that it flops worse than a basic strategy. The more dimensions, the more ironic the use is intended to be.

That being said, while versions of 3D chess exist, I couldn't easily find any playable four dimensional variations. I thought rather than digging through the internet for one, it would be a good test of my own spatial reasoning and abstract design skills to create my own version then balance the movement and eventually play it seriously/competitively.

What it does

It creates then runs a 2 player game of four dimensional chess. It has a very rough but still understandable GUI housing a 2 dimensional representation of the board's 4 dimensions. It determines what moves each player could make and displays those options in an intuitive manner.

How I built it

The software is entirely in Java dispersed unevenly among a fair few classes; I used IntelliJ IDEA for this project. The few images used were made in GIMP 2, but they are pretty obviously not the most impressive chess pieces I've mocked up. The two images used for knights come courtesy of Amazon.com. The board itself is designed around the 5x5x5 Raumschach version of 3D chess, becoming a 5x5x5x5 board with 1 king, 2 queens, 6 bishops, 8 knights, 8 rooks, and 25 pawns each. I took inspiration from Raumschach in how I positioned them, but the design is mine. I believe it allows for possibly interesting opening tactics while still looking, feeling, and playing balanced.

Challenges I ran into

There were a few key road bumps on the project

1) Defining and visualizing the movement was much more difficult than I had anticipated

I got skeleton code down fast, but once it came time to start defining what each piece could do, I ended up redefining what each could do multiple times. What does it mean for a pawn to reach the opponent's home row when the home row could be considered anything from a row to an entire cube in 4 dimensions. Should I allow pieces that move diagonally theoretically move diagonally across 3 or 4 dimensions at once? I ended up settling on a set of rules, but much later than anticipated. How do I make it clear that a critical move that may be hidden by the change of dimensions is still visible and accessible to the player? Unfortunately, I still my solution of highlighting possible moves and key information as a bit crude, but given the time constraints it's good enough.

2) Checking if a move is valid becomes very difficult since a player cannot move into a position that puts or leaves them in check

This ones just poor prep on my part, but it's still a hump in the project I had to deal with. I hadn't thought about the complexity of the problem nor how it grows with the scaling of dimensions. As a result of a lack of prep work, my solution is quite a bit less efficient than I had hoped since I had to patch together solutions, but I was able to squeeze in a few optimizations in the time allotted.

3) Restructuring my core class

I wanted to display what piece in particular was putting a player in check as I noticed it was near impossible to tell immediately with the display style I had committed to, but with the methods I had already written, that would be incredibly difficult to trace back since the objects I had my classes was passing around was just the bare minimum of what location on the board it referred to to save on time and space. To find what piece was targeting the king from there wasn't possible, so I had to rewrite a large amount of the project to also pass around what type of piece the location data referred to as I was using "phantom" locations and pieces to represent possible future moves.

4) Graphics

It's been a while since I've done any sort of legitimate GUI in Java and decided this was the perfect time to relearn Swing and AWT. As a result it looks like a controlled mess at best. The poor quality of the background made me less motivated to redraw the sample piece images I quickly threw together for testing. Certainly a higher quality UI would make comprehending the state of the board easier, but I just didn't have the time to do it during the hackathon.

Accomplishments that I'm proud of

I got it done and didn't skimp on sleep or other necessities

I'm still new to hackathons, so I'm happy with crossing the finish line with a functioning project I'm proud of working on this weekend without depriving myself of sleep.

I figured out Swing and AWT again

It's always good to come away learning something!

What I learned

I either go all out on graphics or not at all

Identifying this will be important for the future. When I sit down to design/draw I'll be a perfectionist with it. When I sit down to code, I'll kick the deisgn to the curb. Knowing what to expect means better results and the ability to change.

4D Chess is hard

It's no joke despite being literally a joke.

What's next for 4D Chess

1) a better UI

2) a much better UI

3) displaying a whole 3 dimensional playspace at once to make dimension swapping more intuitive (i.e. a better UI)

4) performance optimizations especially in the time it takes to find the valid moves for a player

5) an 8x8x8x8 version that would allow for moves banned by Raumschach like pawns taking 2 spaces, en passant, and castling.

Built With

Share this project:

Updates