Sie sind auf Seite 1von 17

ROCK PAPER SCISSORS

Alejandro, Joel Amos


Ante, Kenn

INTRODUCTION

Humans strive to improve their own lifestyle or their way of living


simply by creating new machineries and stuffs. These machineries,
however, does not think by itself. So, through the powerful mind of the
humankind, the concept of Artificial Intelligence was conceived. One can
define this as the study and the design of creating, an artificial
intelligence[1].
Through this definition, it can be perceived that this idea can make
enormous amount of benefits to the lives of the humankind. Furthermore,
it gives, somehow a “life” to the machineries. In terms of the video
gaming industry, AI is vital to the game’s gameplay, especially nowadays
that the games offered are interactive. The higher the AI of certain things
in the game, the more challenging, unpredictable and fun it is.

I. DESIGN OF THE PROGRAM

Video games today continue to prosper; in the midst of undeniably


loads of problems the world faces today, such as poverty and
environmental-related issues, and in this documentation, the group wishes
to discuss a bit about the information regarding the Visual Basic.

The beginning of Visual Basic era marked the breakthrough in


intellect and stylish programming. Visual Basic, rooting from various C and
C++ versions, enables the programmers to create endless and unique
programs ranging from matrices, calculators and even the video games –
may it be simple or complex. This application has a wide array of
capabilities that programmers can fully utilize. Visual Basic also had
handful of external applications, like the SDL, which allows for creating
simple games. The SDL info was discussed in the previous documentation.

Visual Basic (VB) is the third-generation event-driven programming


language and integrated development environment (IDE) from Microsoft
for its COM programming model. VB is also considered a relatively easy to
learn and use programming language, because of its graphical
development features and BASIC heritage. [2]
With the VB instilled in the programming skills of the users, the
group is now introduced in the concept of AI. Artificial Intelligence (AI)
is the area of computer science focusing on creating machines that can
engage on behaviors that humans consider intelligent. The ability to
create intelligent machines has intrigued humans since ancient times,
and today with the advent of the computer and 50 years of research
into AI programming techniques, the dream of smart machines is
becoming a reality. Researchers are creating systems which can mimic
human thought, understand speech, beat the best human chessplayer,
and countless other feats never before possible. Find out how the
military is applying AI logic to its hi-tech systems, and how in the near
future Artificial Intelligence may impact our lives. [3]

Rock-paper-scissors is a hand game played by two or more people.


The game is known by many names, including 'rock-scissors-paper',
paper-rock-scissors, paper-scissors-rock, fargling, cachi-pún, scissors-
paper-rock/stone, jan-ken-poy, "jenken" kauwi-bauwi-bo, камень-
ножницы-бумага and rochambeau.

The game is often used as a selection method in a way similar to


coin flipping, drawing straws, or throwing dice. However, unlike truly
random selection methods, rock-paper-scissors can be played with a
degree of skill, especially if the game extends over many sessions with
the same player(s); it is often possible to recognize and exploit the
non-random behavior of an opponent. [4]

[5]
Figure: Example rock paper scissors game

Goal
The goal of Rock Paper Scissors is to choose the item (rock, paper
or scissors) which defeats your opponent’s chosen item.

Setup

Players face each other and create a fist using the hand they will
use to play.

Gameplay

The players simultaneously countdown from three. (i.e., They say,


"Three, two, one, go.") When the players say "go," they each use a
hand to create the shape of their chosen item, as follows:

•Rock is represented by a closed fist.


•Scissors are represented by a closed fist with two fingers (the
pointer finger and the middle finger) extended.
•Paper is represented by an open hand.
Winning

The winner of Rock Paper Scissors is determined as follows:

•Rock defeats (breaks) Scissors.


•Scissors defeats (cuts) Paper.
•Paper defeats (covers) Rock.
If both players choose the same item, the game is a tie and they
play again.

Players can choose to play a predetermined number of rounds, such


as best two out of three, or best three out of five. [6]

Figure: rock paper scissors rules [7]


The program seeks to combine the concept of AI in the game
through the SDL and VB.
II. THE PROGRAM

PROGRAM

int l=0; int m=0; int k=0; bool evention = true;

int mouse1=0; int over=0; int crude=0; int crud(int, int);

int move1=0; int move2=0; int score1=0; int score2=0;

int mode =0; int check1=0; int crude1=0;

// this function draws the tilemap on the screen.

void DrawTilemap( int p_x, int p_y )

int x, y, z;

int bx = p_x;

int by = p_y;

int index=0;

// loop through every layer


for( z = 0; z < LAYERS; z++ )

bx = p_x;

by = p_y;

// then loop through each x,y on each layer.

for( y = 0; y < MAPHEIGHT; y++ )

for( x = 0; x < MAPWIDTH; x++ )

// get the tile number in the cell

index = g_tilemap.Get( x, y, z );

// if the tile is valid, then draw it.

if( index != -1 )

SDLBlit( g_tiles[index], g_window, bx, by );

bx += TILESIZE;

// reset the bx counter back to the beginning x pixel

bx = p_x;

// increment the by pixel counter

by += TILESIZE;

int crud(int x, int y)

{
int a;

int b;

for( a=0; a<=x; a++)

for(b=0; b<=y; b++)

crude= 5*b + a;

return crude;

int main( int argc, char* argv[] )

// declare coordinates.

int x, y;

SDL_Event event;

// initialize the video system.

SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );

SDL_WM_SetCaption( PROGRAM_NAME, 0);

atexit( SDL_Quit );

g_window = SDL_SetVideoMode( WIDTH, HEIGHT, 0, SDL_ANYFORMAT );

// load the bmps

- See the program for the names of the bitmaps

SDL_SetColorKey( g_tiles[20], SDL_SRCCOLORKEY,


SDL_MapRGB( g_tiles[20]->format, 0, 0, 0 ) );

while (check1 == 0)

while ( 1)

if( SDL_PollEvent( &event ) )

instructions = SDL_LoadBMP( "title.bmp" );

SDL_FillRect( g_window, NULL, SDL_MapRGB( g_window-


>format, 0, 0, 0 ) );

SDLBlit (instructions, g_window, 0, 0);

SDL_UpdateRect( g_window, 0, 0, 0, 0 );

if( event.type == SDL_MOUSEBUTTONDOWN )

check1= 1;

break;

while ( check1 == 1 )

while ( 1)

if( SDL_PollEvent( &event ) )

instructions = SDL_LoadBMP( "instruct1.bmp" );

SDL_FillRect( g_window, NULL, SDL_MapRGB( g_window-


>format, 0, 0, 0 ) );

SDLBlit (instructions, g_window, 0, 0);

SDL_UpdateRect( g_window, 0, 0, 0, 0 );

if( event.type == SDL_MOUSEBUTTONDOWN )


{

check1= 2;

break;

while ( check1 == 2 )

while ( 1)

if( SDL_PollEvent( &event ) )

instructions = SDL_LoadBMP( "instruct2.bmp" );

SDL_FillRect( g_window, NULL, SDL_MapRGB( g_window-


>format, 0, 0, 0 ) );

SDLBlit (instructions, g_window, 0, 0);

SDL_UpdateRect( g_window, 0, 0, 0, 0 );

if( event.type == SDL_MOUSEBUTTONDOWN )

check1= 3;

break;

instructions = SDL_LoadBMP( "rockright.bmp" );

for( y = 0; y < MAPHEIGHT; y++ )

for( x = 0; x < (MAPWIDTH / 2); x++ )

{
g_tilemap.Get( x, y, 0 ) = 0; //rand() % 4;

g_tilemap.Get( x + (MAPWIDTH / 2), y, 0 ) =0;//rand() %

g_tilemap.Get( 0, 0, 0 ) = 12; g_tilemap.Get( 1, 0, 0 ) = 11;

g_tilemap.Get( 3, 0, 0 ) = 10; g_tilemap.Get( 4, 0, 0 ) = 9;

g_tilemap.Get(4, 3, 0 ) = 8; g_tilemap.Get( 4, 4, 0 ) = 7;

g_tilemap.Get( 0, 3, 0 ) = 6; g_tilemap.Get( 1, 3, 0 ) = 5;

g_tilemap.Get( 2, 3, 0 ) = 4; g_tilemap.Get( 1, 4, 0 ) = 3;

g_tilemap.Get( 2, 2, 0 ) = 2; g_tilemap.Get( 2, 1 , 0 ) = 1;

g_tilemap.Get(1,0,0) =16; g_tilemap.Get(4,0,0) =16;

g_tilemap.Get(2,0,0) =8;

g_tilemap.Get( x, 2, 0 ) = 1;

g_tilemap.Get( x, 6, 0 ) = 1;

for( y = 3; y < 7; y++ )

g_tilemap.Get( 1, y, 0 ) = 1;

g_tilemap.Get(4 , y, 0 ) = 1;

*/

// clear the second layer

for( y = 0; y < MAPHEIGHT; y++ )

{
for( x = 0; x < MAPWIDTH; x++ )

g_tilemap.Get( x, y, 1 ) = -1;

x=0;

y=0;

over=0;

while( evention )

//look for an event

if( SDL_PollEvent( &event ) )

//an event was found

if( event.type == SDL_QUIT )

break;

if( event.type == SDL_MOUSEBUTTONDOWN )

SDL_GetMouseState( &x, &y );// get the mouse


state.

x= x/64;

y= y/64;

crud(x, y);

if (crude ==15 )

move1 =1;
rock= SDL_LoadBMP( "rockleft.bmp" );

//instructions = SDL_LoadBMP( "rockright.bmp" );

else if (crude == 16)

move1 =2;

rock= SDL_LoadBMP( "paperleft.bmp" );

else if (crude == 17)

move1 = 3;

rock= SDL_LoadBMP( "scissorleft.bmp" );

else if (crude == 19)

mode =0;

g_tilemap.Get(2,0,0) =8;

else if (crude == 21)

break;

else if (crude == 24)

mode = 1;
g_tilemap.Get(2,0,0) =7;

else{}

move2 = 2;

if (crude ==15 )

move1 =1;

rock= SDL_LoadBMP( "rockleft.bmp" );

else if (crude == 16)

move1 =2;

rock= SDL_LoadBMP( "paperleft.bmp" );

else if (crude == 17)

move1 = 3;

rock= SDL_LoadBMP( "scissorleft.bmp" );

if (move1 == 1 || move2 == 2)

score2++;

else if (move1 == 2 || move2 == 1)

{
score1++;

else if(move1 == 3 || move2 == 1)

score2++;

else if(move1 == 1 || move2 == 3)

score1++;

else if(move1 == 2 || move2 == 3)

score2++;

else if(move1 == 3 || move2 == 2)

score1++;

else

//draw

if( event.type == SDL_MOUSEBUTTONUP )

// get the mouse state.


SDL_GetMouseState( &x, &y );

if( event.type == SDL_KEYDOWN )

// a key was pressed.

if( event.key.keysym.sym == SDLK_ESCAPE )

// if ESC was pressed, quit the program.

SDL_Event quit;

quit.type = SDL_QUIT;

SDL_PushEvent( &quit );

if( event.key.keysym.sym == SDLK_UP )

g_dy += SCROLL;

if( event.key.keysym.sym == SDLK_DOWN )

g_dy -= SCROLL;

if( event.key.keysym.sym == SDLK_LEFT )

g_dx += SCROLL;

if( event.key.keysym.sym == SDLK_RIGHT )

g_dx -= SCROLL;

if( event.type == SDL_KEYUP )

if( event.key.keysym.sym == SDLK_UP )

g_dy -= SCROLL;

if( event.key.keysym.sym == SDLK_DOWN )


g_dy += SCROLL;

if( event.key.keysym.sym == SDLK_LEFT )

g_dx -= SCROLL;

if( event.key.keysym.sym == SDLK_RIGHT )

g_dx += SCROLL;

} // end event loop.

g_x += g_dx;

g_y += g_dy;

// clear the screen to black.

SDL_FillRect( g_window, NULL, SDL_MapRGB( g_window->format, 0,


0, 0 ) );

DrawTilemap( g_x, g_y );

SDLBlit(rock, g_window, 0, 64 );

SDLBlit( instructions, g_window, 192, 64 );

// update the entire window.

SDL_UpdateRect( g_window, 0, 0, 0, 0 );

// done

return 0;

III. EXPERIMENT DETAILS

The program showed the following:

O Display bitmaps of different types

O Tiling manipulation
O Key press manipulation with the esc key

O Tile Identification algorithm

O Event Driven handling

O Adjacent tile algorithm

O Has menu

O Color Keying

O The ability to overload windows

O Has title, intro, instructions

IV. CONCLUSION AND RECOMMENDATION

Although the game was created in a simple manner, the mere concept
of Artificial Intelligence was prevalent in the program. There are menus, like
the exit button, which gave more life to the game. Though, the game can be
better improved on the visuals, and also smoother flow of the game. Even if
the game uses simple AI and graphics, it is a fun game that is sure to enjoy
people during their breaks.

V. REFERENCES

[1] Artificial Intelligence. Retrieved from


http://en.wikipedia.org/wiki/Artificial_intelligence as of 30 August 2010.

[2]Visual Basic Resource Center. Retrieved http://msdn.microsoft.com/en-


us/vbasic/ms788229.aspx as of 30 August 2010.

[3] Artificial Intelligence – Introduction to the science of AI. Retrieved from


http://library.thinkquest.org/2705/ as of 31 August 2010.

[4] Rock Paper Scissors. Retrieved from


http://en.wikipedia.org/wiki/English_draughts as of 30 August 2010.

[5] Rock Paper Scissors Photo. Retrieved from


http://img.brothersoft.com/screenshots/softimage/r/rock-paper-
scissors_portable-275709-1250748084.jpeg as of 30 August 2010.
[6] Rock Paper Scissors Rules. Retrieved from
http://boardgames.about.com/od/partygame1/a/rps_rules.htm as of 1
September 2010.

[7] Rock Paper Scissors. Retrieved from


http://52statesin8months.files.wordpress.com/2009/02/rock_paper_scissor
s.jpg
as of 1 September 2010.

Das könnte Ihnen auch gefallen