Yeah, I'm a code artisan

>yeah, I'm a code artisan

Attached: mCAaI68.png (1351x960, 980K)

Other urls found in this thread:

youtu.be/R9c-_neaxeU
twitter.com/NSFWRedditGif

There's only 8 possible options to win if you're using an array of 9 elements.
Considering
0 1 2
3 4 5
6 7 8
the options are
0 1 2, 3 4 5, 6 7 8,
0 3 6, 1 4 7, 2 5 8,
0 4 8, 3 4 7.
I'm sure you'll be able to figure out the rest.

Last one should have been 2 4 6.

This is still better code than 99% of Jow Forums

What a waste of lines.

yanderedev is that you

>people write shit like this
>meanwhile I have a book from decades ago that describes a self-learning tic-tac-toe AI made of fucking MATCHBOXES

Cool, now write the minimax algorithm for it.

Same here man. Do you have a gofundme?

Attached: programming abomination.png (1920x1039, 236K)

>tfw i get btfo in /dpt/ over the smallest things anonymously and yet people post this kind of sht in public and they are proud

Attached: Gooby_car_suspicious.png (386x269, 42K)

Should have made a board object with a getState() function to know if someone won. OOP best paradigm

/dpt/ has some standards
nornalniggers literally have no clue what they're looking at when they see code

>not writing a tensor to solve tic-tac-toe

>using math for the sake of using math

How do you do this in a non-retarded way? If you have only a board state you need to do 8 checks (can be put in a nested loop to save lines)

24*

ls
cd ..
ls
cd ..
ls

function checkVictory(board){

for(var z = 0; z < 4; z++){
for(var y = 0; y < 3; y++){
var sum = 0;
for(var x = 0; x < 3; x++){
sum += z == 0 ? board[x][y] : 0;
sum += z == 1 ? board[y][x] : 0;
sum += z == 2 ? board[x][y++] : 0;
sum += z == 3 ? board[x][2 - y] : 0;
}
if(sum == 0 || sum == 3){
return true;
}
}
}

Source/title of book pls?

>Not making a function of type Board -> Maybe Player or something like that.
OOP is literally spaghetti code, and I can't wait for these old fucks who still swear by it to die.

How would you do it?

>have a list of lists of wining indicies
>look whether any of them has one where all entries are equal to each other and aren't empty
>return said value (the player that won) or that nobody has

Represent the board state as a bitmask.
Then there are 8 known win values, just check against those.
I don't think there's any way to do this without introducing an O(n^2) calculation somewhere, but doing a bitmask then checking against known values at least means that the bitmask itself is the only O(n^2) part, as the checks each are O(1) and there are 2n + 2 values to check against (which could even be made O(1) by just having an array where the indices are the values the bitmask could have and the values are just whether it's a win or not. This would be inefficient from a memory standpoint (array size would be n^2) but efficient from a time standpoint.

You could actually make the whole thing O(n) if the bitmask *was* the authoritative store of the board state, but that's trickier to do.

>detectVictory

Into the trash it goes

This code is fucking cancer holy fuck.

I'm not totally opposed to this approach, it would be fast. The state-space of the game is 3^9, which is about 19683 possible combinations. Some of which should never be possible, but that shouldn't matter as long as the win condition is checked every game-step. So that's just a bit-field of size ~2.5kB, all you would need is a function to convert to board into its representative number.

1 for game over, 0 for game still in progress; if 1 than the last player to move is the winner. Classic example of trading space for compute. I wouldn't outright reject this line of reasoning in an interview, provided the applicant didn't write a retarded series of 'if' statements like this. But something like brute forcing all possible games offline, and storing the results to a packed binary representation would be fine.

Even better would be just to brute force the winning states, convert to binary, and just check those every game step.

Wait a minute is that narcissa?

I'm not the guy, but this is an interesting video demonstrating the concept: youtu.be/R9c-_neaxeU

do NOT bully klossy plz

I know this is like the proof of concept bare minimum, but what stops it getting stuck in some sort of local optimum, like making a centre move was settled on but that might block that the "path" to better minima.

If the interfaces are well-documented and accessors are used then OOP cannot lead to spaghetti code