This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-03-13 17:17:51

rukichan
Scratcher
Registered: 2010-12-29
Posts: 29

How do you make a computer opponent???

im trying to make a capture the flag type thing and i want it to be one player, so how do i make it so the computer will be the opponent and respond to whatever the person playing it does? sorta like when u play checkers on ur ipod or whatever the ipod 'thinks' like a couple of moves ahead, sorta like that!

i already figured out how to make the sprite move when someone presses the arrow keys, i just need to find how to make it go for as long as the arrow keys are pushed.

i know that was confusing but someone please help me!


When life gives you lemons, squirt them in your enemy's eyes!
I'm not random, you just can't think as fast as me.

Offline

 

#2 2011-03-13 17:49:10

majormax
Scratcher
Registered: 2008-04-06
Posts: 1000+

Re: How do you make a computer opponent???

Maybe look at this article about the computer players.

Offline

 

#3 2011-03-13 23:05:24

silvershine
Scratcher
Registered: 2010-11-21
Posts: 500+

Re: How do you make a computer opponent???

Hmm, it sounds like what your doing is pretty complex. If your goal is for the computer opponent to try to "tag" the player, use a script like this:
[blocks]
<when green flag clicked>
<forever>
<point towards( Player )>
<move( 10 )steps>
[/blocks]
(You can change the number of steps it moves to whatever you want.)

If you want a script for the computer that try's to run away from the player, try a script like this:
[blocks]
<when green flag clicked>
<forever>
<point towards( Player )>
<turn cw(180 )degrees>
[/blocks]
(this script will work best in full screen mode)



I hope that helps you!


Silvershine

Offline

 

#4 2011-03-14 17:31:05

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How do you make a computer opponent???

The checkers method of thinking ahead is by using a game tree.  This wouldn't work for a capture the flag type game, there are simply too many possibilities

Example: 2 people on each team can all move 4 directions, so in each given frame, there is a combination of 16 different "moves".  To think 8 frames ahead, there are 16^8 or about 4.3 billion possibilities to be looked at, and no computer can handle that every frame!


Instead, I would base my AI off of distance between the opponents, the opponents' flag, and the center line.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2011-03-15 18:56:35

joxa
New Scratcher
Registered: 2010-07-20
Posts: 1

Re: How do you make a computer opponent???

Ai codes use vaiables and random factors so if you don't know variables you can't make an ai for my ai project boss battles the biggest problem i have is making the computer less invincible without put an increased wait time on all attacks which would pretty much make the computer player an easy target for attacks

P.S. the trick to beating my ai is to stay in the air because even though i made a script to defend it from air attacks it activates the script at random times.

Offline

 

Board footer