• Create Account

# afmack

Member Since 15 Jun 2012
Offline Last Active Oct 10 2012 02:50 AM

### Rock Paper Scissors Lizard Spock in Python

10 October 2012 - 02:36 AM

So, I'm doing this assignment and I cannot figure out what I'm doing wrong. I'm supposed to find the difference between the player's number and computer's number and then use modulus division. I then use the resulting number to decide on whether the computer or the player wins the hand. For some reason though python seems to be skipping my else statement or something. Any help would be appreciated.

```def number_to_name(number):

if number == 0:
name = "rock"
return name

elif number == 1:
name = "Spock"
return name

elif number == 2:
name = "paper"
return name

elif number == 3:
name = "lizard"
return name

elif number == 4:
name = "scissors"
return name

def name_to_number(name):

if name == "rock":
number = 0
return number

elif name == "Spock":
number = 1
return number

elif name == "paper":
number = 2
return number

elif name == "lizard":
number = 3
return number

elif name == "scissors":
number = 4
return number

def rpsls(guess):

import random

player_number = name_to_number(guess)
comp_number = random.randrange(0, 5)
winner = (comp_number - player_number) % 5

print ""
print "Player chooses " + number_to_name(player_number)
print "Computer chooses " + number_to_name(comp_number)

if (comp_number - player_number) % 5 == 1 or 2:
print "Computer wins!"
elif (comp_number - player_number) % 5 == 0:
print "Player and computer tie!"
else:
print "Player wins!"

rpsls("rock")
rpsls("Spock")
rpsls("paper")
rpsls("lizard")
rpsls("scissors")

```

### Memory Allocation

01 July 2012 - 03:39 AM

Hello, I'm learning memory allocation online right now and I'm having some issues. I'm trying to create the size of an array in run-time and I seem to be having some issues. When I code it all inline it works fine, but when I put it in a function I seem to be doing something wrong. I keep getting this error on Visual Studio: error C2082: redefinition of formal parameter 'a'

Here's the code.

```#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
void randomArrayFill( int *a, int size )
{
int *a = new int[size];
for( int i = 0; i < size; i++ )
{
a[i] = rand() % 100;
}
}

int main()
{
//----Init--------------------------------------------------------------
int size = 0;
int *a = 0;
srand(0);
//----End Init----------------------------------------------------------
cout << "Enter the size of an array to create: ";
cin >> size;

randomArrayFill( a, size );
for( int i = 0; i < size; i++ )
{
cout << a[i];
}
cin.get();
cin.get();
return 0;
}
```

### -Help with some code-

23 June 2012 - 03:18 AM

Hello, I'm workin' on a slot machine program and for some reason I'm having some issues with the menu. Selecting one breaks out of the menu loop and will allow you to play the slot machine game. Selecting two quits the game. And anything else it prints onto the console "Please enter a valid option." For some reason, when an invalid number is entered it prints but it doesn't loop back. So yeah, slightly confused. *I apologize, but the code snippet tool was not cooperating with me, only showing a portion of whatever code I put in*

Here's the code:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int Random( int, int );

int main()
{
//---- Initialization-------------------------------------------------
int low;
int high;
int chips = 1000;
int hold = 0;

bool quit = false;
//----End Init--------------------------------------------------------

// Start Game---------------------------------------------------------
while( !quit ){
while( hold <= 0 )
{
cout << "Player's chips: \$" << chips << endl;
cout << "1) Play slot. 2) Exit." << endl;
cin >> hold;

if ( hold == 1 )
break;
if ( hold == 2 )
quit = true;
else
cout << "Please select a valid option" << endl;

}
}

cin.get();
cin.get();

return 0;
//---End Game---------------------------------------------------------
}

int Random( int low, int high )
{
srand(time(0));

int a = (rand() + low) % high;
return a;
}

### Learnin' DirectX

15 June 2012 - 11:29 AM

Hello, I'm in the process of learning DirectX 11 with the book "Beginning DirectX 11 Game Programming". I'm using Microsoft Visual Studio '10 and I'm trying to get a blank window running.

Here's the code I'm running:

```#include <Windows.h>
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT paintStruct;
HDC hDC;
switch( message )
{
case WM_PAINT:
hDC = BeginPaint( hwnd, &paintStruct );
EndPaint( hwnd, &paintStruct );
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0;
}
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow )
{
UNREFERENCED_PARAMETER( prevInstance );
UNREFERENCED_PARAMETER( cmdLine );
WNDCLASSEX wndClass	= {0};
wndClass.cbSize		= sizeof( WNDCLASSEX ) ;
wndClass.style		 = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc   = WndProc;
wndClass.hInstance	 = hInstance;
wndClass.hCursor	   = LoadCursor( NULL, IDC_ARROW );
wndClass.hbrBackground = (HBRUSH ) (COLOR_WINDOW + 1 );
wndClass.lpszClassName = "DX11BookWindowClass";
if( !RegisterClassEx (&wndClass ) )
return  -1;
RECT rc = { 0, 0, 640, 480 };
HWND hwnd = CreateWindowA( "DX11BookWindowClass", "Blank Win32 Window",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,
rc.bottom-rc.top, NULL, NULL, hInstance, NULL );
if(!hwnd)
return-1;
ShowWindow( hwnd, cmdShow );
// demo init
MSG msg = { 0 };
while( msg.message != WM_QUIT )
{
if ( PeekMessage(&msg, 00, 0, 0, PM_REMOVE) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else{
// Update
// Draw
}
}
// Demo Shutdown
return static_cast<int>( msg.wParam );
}
```

The error I'm receiving is: error C2440: '=' : cannot convert from 'const char [20]' to 'LPCWSTR' .
For the line: wndClass.lpszClassName = "DX11BookWindowClass";

Any ideas as to how I can fix this?

PARTNERS