Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Creating a card game, and the opponent AI *just point me in the right direction*

Author
Message
ragnarox
9
Years of Service
User Offline
Joined: 4th Oct 2015
Location:
Posted: 20th Oct 2015 12:20
So, with no previous knowledge in programming apart from a few college courses, I've managed to flesh out my game: the main menu, art selection, online/offline selection, and so on. The 'skeleton' of my game is finished. The stuff that I can do with a basic knowledge of programming and the help of some tutorials.

Now, I need to sit down and actually program the game itself. It's a traditional card game quite popular where I am from, and it has 4 players, with 2 people on each team, quite similar to Spades.

I'm not asking someone to tell me exactly how to program it (unless you're feeling particularly charitable ), I just need you guys to tell me what programming topics/functions I need to sit down and read about, so that I can come back to this and know what I need to do.

For example, how do I tell my application that a game has started or ended? How do I create the opponent AI in case of an offline match (I assume this includes a monster "if" statement)? Is it possible to create a separate do...loop when the player is inside a match, totally separate from the one used to make the main menu work? Or do I simply set a global variable to check if the player is inside a match and work within the same loop?

I know that AppGameKit v2 is based on the BASIC programming language...are they similar enough so that I could use learning resources for BASIC to help me understand what I need to do here?

I'm looking for advice, tutorials, anything. Help me find my way!

Thank you.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Oct 2015 13:40
Quote: "For example, how do I tell my application that a game has started or ended? How do I create the opponent AI in case of an offline match (I assume this includes a monster "if" statement)? Is it possible to create a separate do...loop when the player is inside a match, totally separate from the one used to make the main menu work? Or do I simply set a global variable to check if the player is inside a match and work within the same loop?"


All of this is covered by a concept called a "Finite State Machine". Googling this will give you a wealth of information.

Rather than lots of IF statements, you use SELECT / CASE.
Each State is a CASE (e.g RUN, WALK, SHOOT, HIDE)
You run the CASE for the State you are in
At the end of each CASE you decide whether you are in the same State, or a different one.

States represent the game itself (Pick up card, analyse cards, play card etc)
and can represent the game progress (Play Game, Start Game, End Game)
You embed state machines within each other for finer granularity of control.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 20th Oct 2015 14:14
Quote: "RUN, WALK, SHOOT, HIDE"
Says a lot about how you play cards Hahaha
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Oct 2015 14:43
AI can often be boiled down to simply choosing the best move, which is especially useful in board games like Chess, where distinct possible actions can be measured. Chess AI in particular is a case of calculating the value of the board for each player, and iterating through every possible move, then comparing the value of the board. Not every move will increase or decrease the value, but calculate a few moves ahead and the AI can pose a real challenge. Like, really Chess AI is looking for the first move in a series of moves that will win the game - and it's all done with piece valuation, with the King being exponentially higher valued than the other pieces (which are typically valued depending on the number of squares they can attack as well as if they are under threat from an opponent piece. With these fairly straightforward rules, Chess AI will defend and attack and play a decent game, you could say that Chess AI is a challenge of data management rather than clever programming.

The same basis could apply to your card game. If each player takes a turn, and there's a finite number of moves they can make, then calculate a value for each move, then if it's possible, calculate the opponent moves as well, and drill into layers of possible future moves, looking for the best scoring initial moves. Hope that makes sense.

If, just for an example, you have a card game with 2 players, and each player has 5 cards, and 1 card in the middle, the players can either put a card down of the same suit, or a card down of the same value. So if there's a 5 of hearts in the middle, and the player has a 2 of hearts, 3 of hearts, 5 of clubs, 6 of diamonds, and 3 clubs... They could play the 2 or 3 of hearts, or play the 5 of clubs, changing the suit - but that might not be a good move because there's still the 2 and 3 of hearts, changing the suit would make it more difficult to get rid of those. You AI might calculate the value of the players hand, and if a card matches the suit, adjust the value of that move, and the AI will favour moves that retain a suitable face card. The AI might suggest playing the 2 of hearts, then the 3, then the 3 of clubs, leaving just the 5 of clubs, and the 6 of diamonds. If an opponent changes the suit, then the AI would adjust - like if the 2 is played, then an opponent plays a 2 of clubs, then the AI would favour playing the 5 of clubs, then the 3 of clubs, then the 3 of hearts and on and on.

So I suggest that you consider how the game is played, what moves are valuable, how can you score a players hand to compare different possible moves. I think that the old fashioned Chess brute force method of assigning values and calculating scores would provide awesome AI, like scary stuff that will beat you, it can get very interesting once you start to meddle with this stuff.
ragnarox
9
Years of Service
User Offline
Joined: 4th Oct 2015
Location:
Posted: 20th Oct 2015 22:36
^ Yea, even though it's gonna be tough to program I think the AI will be the funnest part of this whole thing. Especially since I need to make sure the computer plays conservatively in case they are paired with a human player - allowing the human to call the shots for the team and not making very risky calls.

BatVink - Select / Case seems to be exactly what I need not only to move forward with my project, but also to really simplify some of these huge if/elseif trains I have running in my program. Unfortunately, it feels like I hit a brick wall here - I've been trying to wrap my head around this all day, and I still can't figure out how to move between different cases. How to tell my code to exit one case and move on to another one after a certain button is pressed under certain variable conditions. I'll have at it again tomorrow, it'll click at some point.

Thanks everyone!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Oct 2015 23:02 Edited at: 20th Oct 2015 23:03
I wrote a Space Invaders tutorial years ago for DBPro. This link is part 2, where the State Machine is introduced.
You will see how it moves from state to state. The installer simply unzips the source code and makes a menu link to the code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-11-23 10:27:05
Your offset time is: 2024-11-23 10:27:05