Inspiration
One of my favorite card games as a child was war and I vividly remember the fancy artwork on the large cards of the war deck that I owned. Though this program simply uses integers, it reminded me of a pastime and art that brought much joy to my childhood.
What it does
This program automates the game of war. In brief, players are dealt a hand and flip over the top card in their hand. The winner takes all of the cards from that round. In the event of a tie, the two temporary winners burn a card and play their next card to decide the final winner. If at any point you run out of cards, you are out of the game. The game continues until only one player is left.
How I built it
I simply used Notepad++ and the command window on Windows to build this project. Structurally, each player is represented by a List pointer within a dynamically allocated array. Each list pointer points to a Linked List that contains the players current hand of cards. As cards are played, they are redistributed to the winning players hand as necessary.
Challenges I ran into
The first main challenge was accounting for malloc errors. Since I wanted to dynamically allocate everything, if malloc failed at any point all previously allocated memory had to be freed. This was often very difficult considering how many linkages I had within the base structure of the data type anyways, so to account for every possible scenario was difficult.
The other challenge that I ran into was the event of multiple ties. In the event of a tie, the card after the tie is burned and the next card is played to determine the winner. Though I accounted for a single tie within the program, it was going to be extremely difficult to recursively loop through n-tiebreakers until a distinct winner was finally determined. This is because there could be multiple ties (a 3 way tie) and thus the discarded cards all had to be pushed onto a stack; if at any time someone ran out of cards, they're out of the game but there still may be 2 players fighting for the distinct win. All in all, there a lot of edge cases but the specific case of a tie after a tie was too difficult to recursively implement with my data structures in the given 36 hour timeframe.
Accomplishments that I'm proud of
I'm really proud of combining pretty much all my knowledge from CS1050 and CS2050 in a single project. Within this single program, I successfully incorporated dynamic memory allocation, triple pointers, arrays of pointers, linked lists with dummy nodes, file processing, stack and queue operations, structs, and recursion. There's really not more you could ask from a mechanical engineering major who's only taken those 2 classes and is at his first hackathon.
What I learned
I learned that a seemingly simple game can be extremely difficult to code. I also learned there are a lot of edge cases in the game of war. Most importantly, I learned that there is still a lot to learn about software, development, and computers in order to utilize them to their full potential.
What's next for The Art of War
Once Thanksgiving break rolls around I might try to see if I can recursively implement the tie breaker operation. Other than that, I could implement it the struct with graphics which would bring back many fond memories of the fancy, oversized deck I had as a young boy.
Log in or sign up for Devpost to join the conversation.