• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
LAURENT*

AI is harder than I thought

39 posts in this topic

Don't worry waterlimon the rand operator is in my while loop, Also I got success with the computer randomly picking spots. Unfortunately I now have a logic problem where it only circles's turn once and x turn for the rest of the game.  

0

Share this post


Link to post
Share on other sites

 

 

Um.......................I had this idea to use the rand operator. Not working like I hoped. Anyone thinks this will work?


Depends how you plan to use it really smile.png

Normal use of rand is with modulus like

int i = rand() % 10;

That will give you a random number between 0 and 9 inclusive. If you are trying to pick a random square, that would be the way to use it. Replace 10 with 9 to get an index into the (zero based) array of squares.

 

[insert rant about this method not actually producing uniformly distributed random integers]

 

You need to generate the random integer in a loop, such that if the random integer is at the very end of the range (specifically, larger than MAX_RANGE - MAX_RANGE%10) you throw it away and generate a new one, until you get one that is not a part of that "remainder" at the end of the range (thus the loop)

int range=10;
int rand=randInt();
while (rand > MAX_INT - MAX_INT%range) //if result part of remainder at end of possible random values, regen
{
    rand=randInt();
}
return rand % range;

Though, better read an article written by someone who loves PRNGs to be sure this is correct. ;)

 

 

Indeed, because it is not correct (see how easy it is to get it wrong?). It has a bias towards zero. Test of your code on 8-bit variables, with range 3, over 20 billion trials (there is a bias for every power of two variable size, but it's easier to detect with smaller variables, obviously):

0	6718852175
1	6640484379
2	6640663446

Oops wink.png the fix is to change the comparison to >=, so that the extra element causing the bias is excluded:

/* ... */
while (rand >= MAX_INT - MAX_INT%range)
/* ... */

Which gives (note there are cleaner ways to implement the above that are easier to prove correct):

0	6666558968
1	6666714886
2	6666726146

But this is seriously off-topic for the For Beginners section. I didn't want to reply but I had to, just so someone coming across this post in the future doesn't copy-paste your code and end up with a severe and hard-to-track bug in one of his core functions. Not to mention that trying to robustly generate pseudorandom numbers using a standard library function with an implementation-defined distribution operating on signed integers is just asking for trouble either way happy.png

1

Share this post


Link to post
Share on other sites

 

1) Don't know the name of it - 'game board' is lines of dots. You take away dots on your turn. You win if you opponent picks up the last dot.

It's called Nim, and it has been solved for over a hundred years.

 

 

That would be the one.

 

I know it's been solved (as all simple games of open knowledge have been), but it gives a bit more 'wiggle room' to work with some AI.

 

You can slice it, dice it , analyze it six ways from Sunday but there are only nine squares on a Tic-Tac-Toe board. Rotate the matrix and you have exactly three potential opening moves. You have a few more possibilities for moves 2 and 3 (though many will be 'blunders' leading to an instant win by the opponent), but the number is still small. I was substitute teaching a class for a week and we did a brute force solve of tic-tac-toe on the blackboard one day when I was bored (it was a photography class, and I couldn't give them the free rein with equipment they'd normally have - so there was a lot of 'down time'). It's possible we missed a few cases, and we stopped as soon as it was apparent a move was a blunder (no need to keep checking down that path), but I think we got them all.

 

Something like Nim isn't quite so obviously finite (I know, in reality it is) so I think it would be more fertile ground for developing your own AI algorithm. Especially since not everyone knows the solution - and if you want practice developing an AI, do it for something you don't know the solution for. See how well your AI works, where it falls short, why it loses.

 

It's the 'pong' thing. Pong games have been written for ever OS there is (probably even for some 'smart toasters'). If you want to start to program games, it's still a good place to start. That's how we learn. When there's a known solution we can check our work against, that's even better (usually), or maybe you make your pong game, then look at others and find three different approaches to solving the same problem - again, a good learning experience. 

 

Tic-Tac-Toe doesn't have that kind of 'room' though: a move is either right or wrong, and clearly so. I'm hesitant to even call it AI: If you can win, play the winning move. If you need to block, block. If there's only one or two squares left, play it (or pick one) - game's a tie at that point. After that you load the matrix, compare it to the matrices in the computers list, iterating over the four rotations, and when you find a match, make the move. Done. The computer will never lose a game.

1

Share this post


Link to post
Share on other sites
Snap crackle and pop! I was so thinking of checkers this whole time. I guess I'll still keep at the checkers AI I started on. Haha.

I've started on a tic tac toe AI too. It looks less fuzzy, although for opponent strategy, the offensiveness and defensiveness of the opponent can be fuzzy. However, the fuzziness is overwritten by the exact values. So it is layered.

If a player has two in a row, there is no fuzziness about it, you must block. And if you have two in a row, there is no doubt you must play 3 in a row to win. It is best move to take center on your first move, but one could take a corner.

These are my notes so far before I try to implement it. I am missing a few strategies I know. I still don't think a random move is necessary.

Offense:
-if you have two in a row play 3 in a row. This checks if adjacent squares are not taken first.
-if  not center taken then play center.
Else if not diagonal from center taken then play diagonally from center(check to see if they are taken and play the free one.
-Play adjacent to your pieces.

Defense:
-if opponent  has two in a row, play to block.
-in other words, check which squares they have occupied, and play the unoccupied square adjacent to them.

note to self: play to block could be a dominant strategy.

Victory condition:
If you have three in a row, you win
If they have three in a row, they win

Ai Notes:
What does you win, versus they win mean?
They is opponent (no matter how many)

The logic changes when attitude is a factor.

Defensive player plays to block more often.
Offensive player plays two in a row more often.
Balanced player a balance of defense and offense.
 
 Fuzzy values:
Offensiveness 
Defensiveness

Conditions override fuzzy tendencies. 
0

Share this post


Link to post
Share on other sites

Speaking of randomness and AI, like Lactose said in his first post in this thread, don't make a truly random AI, because it's cheating the players. In most games, players tend to learn their enemies as they play, and take actions according to what they've learned. For example, one learns a monster's behaviors in Monster Hunter and tries to take advantage from them, like by using traps the monster is weak against. Another example is how people learn attack patterns in action games and use that knowledge to defeat the enemy effectively. Players will feel better because they know they've learned something and get better. They won't feel cheated because a monster who appears weak to fire in the beginning turns to be fire-immune on the next stage.

 

Other than that, it also makes it easier to make, because it's easier to make a pre-determined AI than a random one. There's no need to make your AI much more complicated than it needs to be. wink.png

0

Share this post


Link to post
Share on other sites
There's a lot of ways to actually implement AI but just keep in mind even without all the guides and tutorials and such the basic rule of AI in(well most games, not every case of course) games is usually, attempt to seem like a human.

So what does that really mean? Well think about tic-tac-toe, think about if you were playing with a friend and the decisions they might make while playing you, they probably will look at your moves and attempt to block you from winning, most of the time they would succeed at that unless perhaps you used an unusual shape that they might miss easily at one point. Another thing you could do that might be a nice quality of life point is to simulate fatigue of a sort on the computer, i.e. if they keep winning it might slightly increase their chance for a mistake or something.

Basically look at how a competitor or even you might come to decisions and try and emulate that in code, perhaps with some randomization and tweaking. One of the first times I made a rudimentary AI was for a Pong game, I tried a few different things and one of the best ways to make the AI seem more realistic was to make it act like a player. For instance a pong player will generally hover their paddle around the middle when the ball is traveling away from them as they watch for where it is going to bounce to, they also might be slow to respond or overshoot when the ball comes towards them quickly, that sort of thing.

Just some basic AI advice, think what you would do and how you could make the same thing appear with an AI player, sometimes subtle touches a player might not even ever see can make a big difference.
0

Share this post


Link to post
Share on other sites


Bobby Fischer once played a move that was not the "best move" by the book, but because he understood the condition by another reasoning, he actually was playing the game against his opponent (using his pride) and not against the book.

 

Garry Kasparov made a 'finger fumble' in the opening of one of his games against Deep Blue and found the game lost before it ever left the opening stage.

Counting on your opponent's lack of knowledge is seldom a good strategy.

0

Share this post


Link to post
Share on other sites
Well, it seems someone beat me to it. But in this presentation was the exact thing I was talking about. It is a powerpoint on AI (which you might find useful) and later on in the paper it talks about a tic tac toe AI it also mentions fuzzy logic, but I think it is for another example. The steps looks very identical to my steps I listed earlier.

You can use layers, but for tic tac toe, it might not be as necessary, although it would add a nice layer for realism.

http://www.cs.kent.edu/%7Emscherge/AI/Notes/chapter01.ppt
0

Share this post


Link to post
Share on other sites

Min-max is what everyone else was talking about. And that was just an intro to AI lecture. There are thousands of them online.

0

Share this post


Link to post
Share on other sites


it talks about a tic tac toe AI it also mentions fuzzy logic

 

It doesn't, however, mention fuzzy logic in the context of tic tac toe. Its just on the following slide. Give this up.

1

Share this post


Link to post
Share on other sites
Yeah, I know. A few posts ago I acknowledged that I was thinking of checkers and adjusted my reasoning. The adjustment I posted also, and then I found this document, and the adjustment I made for tic tac toe was the same here.

The link was given as a reference to AI, and also to how Fuzzy sets can be used, as well as how Tic tac toe can be done (independent in this case of fuzzy sets).

And I am not going to give up fuzzy logic altogether however, but in the case of tic tac toe, I already noted that it would not be necessary.
0

Share this post


Link to post
Share on other sites

This is the point in a thread that Nathan222 mentions JARVIS normally.

Derailed = true. Sorry if I was any part of that. Just like newcomers to be given decent advice on here.

What are you talking about?
0

Share this post


Link to post
Share on other sites

Listen there is no need to continue.  This thread just needs to go now. 89% of this stuff wasn't really helpful. I'm still a beginner, I've been fighting just to make the computer take a turn because I had no idea how to make the computer press a button in SDL 1.5. You guys are sharp but thread is now pointless.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0