Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Working with GLUT to create a connect 4 program. I\'m struggling to figure out h

ID: 3575220 • Letter: W

Question

Working with GLUT to create a connect 4 program. I'm struggling to figure out how to attach a circle token ( of either black or red depending on the player) to be attached to the mouse . So, the circle always moves with the mouse, and when the player clicks wherever, as long as its a good move, changes the other players color. I have no idea how to do this. I have a cursor function:

void cursor(int x, int y) {} and a drag function: void drag(int x, int y){} and a function for clicking, that I have already implemented. Any ideas?

Explanation / Answer

#This I have implemented in python as you have not mentioned the language that you are using

print " 1 2 3 4 5 6 7 "

def draw(a=[]): def tc(a): if a==0: return " " if a==1: return "X" if a==2: return "Y" print " --------------------------- " print " [%s] [%s] [%s] [%s] [%s] [%s] [%s] "%(tc(a[5][0]),tc(a[5][1]),tc(a[5][2]),tc(a[5][3]),tc(a[5][4]),tc(a[5][5]),tc(a[5][6])) print " [%s] [%s] [%s] [%s] [%s] [%s] [%s] "%(tc(a[4][0]),tc(a[4][1]),tc(a[4][2]),tc(a[4][3]),tc(a[4][4]),tc(a[4][5]),tc(a[4][6])) print " [%s] [%s] [%s] [%s] [%s] [%s] [%s] "%(tc(a[3][0]),tc(a[3][1]),tc(a[3][2]),tc(a[3][3]),tc(a[3][4]),tc(a[3][5]),tc(a[3][6])) print " [%s] [%s] [%s] [%s] [%s] [%s] [%s] "%(tc(a[2][0]),tc(a[2][1]),tc(a[2][2]),tc(a[2][3]),tc(a[2][4]),tc(a[2][5]),tc(a[2][6])) print " [%s] [%s] [%s] [%s] [%s] [%s] [%s] "%(tc(a[1][0]),tc(a[1][1]),tc(a[1][2]),tc(a[1][3]),tc(a[1][4]),tc(a[1][5]),tc(a[1][6])) print " [%s] [%s] [%s] [%s] [%s] [%s] [%s] "%(tc(a[0][0]),tc(a[0][1]),tc(a[0][2]),tc(a[0][3]),tc(a[0][4]),tc(a[0][5]),tc(a[0][6])) print " --------------------------- "

print " 1 2 3 4 5 6 7 "

#valid moves order=[3,2,4,1,5,0,6] def validMoves(intable): global order moves=[] for col in order: for row in range(6): if intable[row][col]==0: moves.append([row,col]) break return moves #moves in slot x acording to valid moves function def move(intable,x,who): val=validMoves(intable) intable[val[x][0]][val[x][1]]=who #Alpha Beta Pruning Search Algorithm def alphabetaPruning(intable, depth): def ab(intable, depth, alpha, beta): values=[]; v=-10000000 for a,s in validMoves(intable): intable[a][s]=1 v=max(v, abmin(intable, depth-1, alpha, beta)) values.append(v) intable[a][s]=0 largest=max(values) dex=values.index(largest) return [dex, largest] def abmax(intable, depth, alpha, beta): moves=validMoves(intable) if(depth==0 or not moves): return eval(intable) v=-10000000 for a,s in moves: intable[a][s]=1 v=max(v, abmin(intable, depth-1, alpha, beta)) intable[a][s]=0 if v >= beta: return v alpha=max(alpha, v) return v def abmin(intable, depth, alpha, beta): moves=validMoves(intable) if(depth==0 or not moves): return eval(intable) v=+10000000 for a,s in moves: intable[a][s]=2 v=min(v, abmax(intable, depth-1, alpha, beta)) intable[a][s]=0 if v <= alpha: return v beta=min(beta, v) return v return ab(intable, depth, -10000000, +10000000) #returns the minutes*60 + seconds in the actial time def time(): return ((gmtime()[4])*60)+gmtime()[5] #Iterative Deepening Search Algorithm def iterDeepening(intable): global order #order=[3,2,4,1,5,0,6] timeout=time()+19 depth=1 res=alphabetaPruning(intable, depth) while True: tStart=time() if abs(res[1])>5000: #terminal node print "Nearly done!" return res[0] tmp=res[0] #chaning the order in considering moves while tmp!=0: order[tmp-1],order[tmp]=order[tmp],order[tmp-1] tmp-=1 depth+=1 res=alphabetaPruning(intable, depth) tEnd=time() runTime=tEnd-tStart if timeout < tEnd+(4 * runTime) or depth > 42: print "DEPTH", depth return res[0]
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote