[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 54 KB, 300x300, costanzacubism.jpg [View same] [iqdb] [saucenao] [google]
4242636 No.4242636 [Reply] [Original]

Rate this code:

http://pastebin.com/ag9nrdn8

It makes a tic, tac, toe game. Run it, faggot.

>> No.4242665

Overly complex code, it's not clear what you're saying. You're using all the wrong structures. I would give you an F+ where + was for trying, but you'll get a plain F because of all that dead and outcommented code.

>> No.4242672

1. Use switch() instead of so many if's

2. For the love of god don't use globals in C++

3. Learn OOP

Overall: 1+/10

>> No.4242680

>>4242672
Well, I ran it and the game dynamics aren't that bad, so I'll give you a fair 3/10 for the whole thing

>> No.4242685

>>4242636
> clusterfuck of if/else's
> a lot of redundant code
> count%2==0 instead of count&1
> no objects in sight
> throwing exceptions for desired logic

>> No.4242695

>>4242685
>>4242672

I haven't learned OOP yet.

Took your other points into account.

By the way, does anyone know how I might automate a bunch or redundant code? For an example, look at the void change_it function. No need to give a long explanation--just tell me what I should learn to do that.

>> No.4242701

>>4242695
Why do you think they invented the subroutines?

>> No.4242710

>>4242695
Use arrays for posX and posX_changed, so you can query them more efficiently and cut out all the redundancy in change_it

>> No.4242715

>>4242695
You've made stupid choices about how to represent your data.

void change_it(int pos, int player)
{
bool success = pos >= 0 && pos < board_size && board[pos] == free;

if(success)
{
board[pos] = player;
success = true;
}

return success;
}

Not the prettiest but you get the idea. You're doing fine for a beginner I suppose.

>> No.4242719

>>4242715
const int X = 0;
const int O = 1;
const int free = 2;
const int board_size = 9;
int board[board_size];

>> No.4242720

>>>/g/res/22178889

Interesting seeing sci vs g

>> No.4242723

it works, so it's good

>> No.4242725

>>4242723
College dropout detected.