Python Forum
Naughts and Crosses win check
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Naughts and Crosses win check
#4
The 'check' function should return True or False regarding win.

Some ideas that might be useful: use set() or all() to determine whether there is 'all-spam' situation:

>>> m = ['spam spam spam'.split(), 'spam ham spam'.split()]
>>> m
[['spam', 'spam', 'spam'], ['spam', 'ham', 'spam']]
>>> for row in m:
...     print(set(row) == {'spam'})
... 
True
False
>>> for row in m:
...     print(all(mark == 'spam' for mark in row))
... 
True
False
To make it more useful any() could be added - to determine is there at least one row with 'all-spam':

>>> any(set(row) == {'spam'} for row in m)
True
>>> any(all(mark == 'spam' for mark in row) for row in m)
True
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Naughts and Crosses win check - by GalaxyCoyote - Oct-09-2019, 08:47 PM
RE: Naughts and Crosses win check - by jefsummers - Oct-10-2019, 12:20 AM
RE: Naughts and Crosses win check - by ichabod801 - Oct-10-2019, 01:56 AM
RE: Naughts and Crosses win check - by perfringo - Oct-10-2019, 05:44 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020