#πŸ”’ how do i evaluate a connect 4 board position?

101 messages Β· Page 1 of 1 (latest)

topaz aspen
#

i have a tablebase of 6000 positions and their relative evaluations, but outside of that, how can i make my own evaluator? and what do i need for it?

vivid needleBOT
#

@topaz aspen

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

topaz aspen
#

any help is appreciated, might have late replies πŸ™

topaz aspen
#

i’ve also heard of minimax and done some research

#

i just need a way to grade a board and i’ll be set

topaz aspen
#

anyone?

#

really?

buoyant gulch
topaz aspen
#

i watched a sebastian lague video on it and i understand the tree searching stuff and recursion a little bit now

#

i just need a way to evaluate the board and i'll be set

#

but how tf do you evaluate a connect 4 board

buoyant gulch
#

I frankly don't have a clue myself, but have you heard about Code Bullet? he mostly does entertainment videos related to programming, but there are specs of technical stuff or, for example, where he has managed to copy the code from 😁
he happens to have a video on connect 4 (it's pretty far from "AI" despite the title...)
https://www.youtube.com/watch?v=XRVA5PMSKKE

topaz aspen
#

the tablebase got me 4 moves into the game 😭

topaz aspen
#

oh wait im dumb

#

i can just use the sources of what code bullet used

#

oh wait

#

i got the test cases from there 😭

topaz aspen
buoyant gulch
#

I'm not entirely sure I will be able to help you with that right now, so uhh... yeah

buoyant gulch
#

honestly all I can suggest is just wait for someone to show up and after some time maybe bump it in python general or if this gets automatically closed, open a new post

desert peak
#

you want to evaluate win conditions?

topaz aspen
#

yeah

#

so if i gave you a position like this:

#

hold on

vivid needleBOT
#

:incoming_envelope: :ok_hand: applied timeout to @topaz aspen until <t:1713992114:f> (10 minutes) (reason: emoji spam - sent 42 emojis).

The <@&831776746206265384> have been alerted for review.

desert peak
#

how are you storing the board state? As a 2d array?

#

mods, do you mind unmuting? They're trying to demonstrate their board's state through emojis and tripped the bot

mystic hare
#

!unmute 566653183774949395

vivid needleBOT
#

:incoming_envelope: :ok_hand: pardoned infraction timeout for @topaz aspen.

mystic hare
#

pls fewer emojis

topaz aspen
#

that was a fast 10 minutes

topaz aspen
#

whats the limit?

mystic hare
#

... 25?

#

don't quote me though

topaz aspen
mystic hare
#

just take a picture and send that though

desert peak
#

don't worry about showing me the board. I think I can help you regardless

#

is it a 2d list?

topaz aspen
#

yes

#

say i had a position like this

#

how would i evaluate it?

#

like how you can eval chess positions

desert peak
#

let's figure this out together

#

we should go top to bottom to avoid checking everything every single iteration

topaz aspen
topaz aspen
#

hold on brb just grabbing smth

desert peak
#

my first guess is to iterate through the outer list until we find a row that isnt empty. Then check the spaces around it.

topaz aspen
desert peak
#

wait, we can optimize further

topaz aspen
#

how in the hell do you map out 8 directions for each of the 42 pieces

desert peak
#

imagine you have a board that's half full

#

assume that the last move wasn't a win

topaz aspen
desert peak
#

well, obviously if we make another move, the positions of the board that weren't near the new piece won't suddenly become wins

#

so we don't need to evaluate the entire board, just the positions near the new piece

#

(and so on, checking for a win condition)

#

like, hold on let me illustrate

boreal summit
topaz aspen
#

i got a half board but its kinda dodgy

boreal summit
topaz aspen
boreal summit
#

Just read it, it's not using any complicated terminology

topaz aspen
#

small text

naive orchid
#

we are just trying to evaluate if the current board is in a win state right?

boreal summit
#

Ah, zoom function

topaz aspen
#

everything else is easy after that

desert peak
naive orchid
#

also i just read about connect4 but correct me if i am wrong u basically win if u manage to connect 4 dots either horizontally, vertically, or diagonally

desert peak
#

so what you should do is:

  1. place a piece
  2. check the spaces immediately surrounding the placed piece (so left, down-left, down, down-right, right)
  3. repeat step 2 for the piece next to it if the colour matches, and do so until until either there are 4 continuous pieces of the same colour in a straight line, or all "routes" are exhausted. Remember though, they must be in a straight line, so you should have a second "checking" function for straight lines, in addition to the initial proximity check
desert peak
#

you're making me want to implement this

#

this could be a fun exercise

topaz aspen
naive orchid
#

do u have a few test cases? @topaz aspen

topaz aspen
#

you can get them here, lemme get a link

#

they dont have a file extension which is kinda odd

desert peak
#

whne you place a piece on the board, that's the only part of the board that changes. Parts of the board that are unaffected by the change won't magically become relevant to determining whether or not the win condition has been met, and you'll only know once you check. Since you have to start the check somewhere, the best place would be to check where the board saw a change (which is where the new piece was placed)

topaz aspen
naive orchid
#

ty

topaz aspen
#

they have the moves and then an eval

#

its supposed to calibrate your solver but idfk how to calibrate it 😭

topaz aspen
vivid needleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.