Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Connect Four game win function
    text
    copied!<p>I have most of my Python version of Connect Four coded, except for the win function and the gravity. Below is the code for determining if the game has been won yet.. It doesn't function, currently the only way the game ends is if all the spots are taken up. Any ideas?</p> <pre><code>winners = [ [1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7],[8,9,10,11],[9,10,11,12],[10,11,12,13],[11,12,13,14], [15,16,17,18],[16,17,18,19],[17,18,19,20],[18,19,20,21],[22,23,24,25],[23,24,25,26],[24,25,26,27], [25,26,27,28],[29,30,31,32],[30,31,32,33],[31,32,33,34],[32,33,34,35],[36,37,38,39],[37,38,39,40], [38,39,40,41],[39,40,41,42],[1,8,15,22],[8,15,22,29],[15,22,29,36],[2,9,16,23],[9,16,23,30],[16,23,30,37], [3,10,17,24],[10,17,24,31],[17,23,31,38],[4,11,18,25],[11,18,25,32],[18,24,32,39],[5,12,19,26],[12,19,26,33], [19,25,33,40],[6,13,20,27],[13,20,27,34],[20,28,34,41],[7,14,21,28],[14,21,28,35],[21,28,35,42],[1,9,17,25], [9,17,25,33],[17,25,33,41],[8,16,24,32],[16,24,32,40],[15,23,31,39],[2,10,18,26],[10,18,26,34],[18,26,34,42], [3,11,19,27],[11,19,27,35],[4,12,20,28] ] def makeMove(self): self.Player = self.game.Player if self.game.Player == 'Black': self.b.config(image=self.Black, command=self.invalidMove) num = self.num self.game.moves['Black'].append(num) self.game.free.remove(num) w = self.won(self.game.Player) if self.game.moves['Black'] in winners: self.game.turninfo.config(text=self.game.Player+' WON!') elif self.game.free == [ ]: self.game.turninfo.config(text='Game is a draw!') else: self.game.Player = 'Red' self.game.turninfo.config(text=self.game.Player+"'s Turn") elif self.game.Player == 'Red': self.b.config(image=self.Red, command=self.invalidMove) num = self.num self.game.moves['Red'].append(num) self.game.free.remove(num) w = self.won(self.game.Player) if contains(self.game.moves['Red'],winners): self.game.turninfo.config(text=Player+' WON!') for c in self.game.cells: c.freeze() elif self.game.free == [ ]: self.game.turninfo.config(text='Game is a draw!') for c in self.game.cells: c.freeze() else: self.game.Player = 'Black' self.game.turninfo.config(text=self.game.Player+"'s Turn") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload