Python for Absolute Beginners Transcripts
Chapter: Problem solving techniques for writing software
Lecture: Demo: Play until someone wins

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The next thing we need to do, that's not checked off is we have to go and play until someone wins. So, notice I put some comments in here
0:08 create the board, choose initial player. I wanted to put that in there to kind of highlight what problem solving bit we were doing.
0:15 Also, I've decided to just call this symbols. I don't want that to be super, super long until we work with it. So here we're going to being doing until
0:25 Well, how do we do that? Remember, I said at the beginning that until a condition is True or False that's going to be a while loop
0:32 and what we have to do is put some kind of test in here like check or find winner. What we want to do is actually go and look through this board
0:42 and see if there's somebody that has X, X, X or O, O, O or more tricky X, X, X and things like that.
0:50 We're not going to do that yet, but because that's complicated let's write a function and pass the board over there
0:57 and maybe we need to pass some more information. For now, I think we're just going to pass the board and we'll say yeah, there's a winner
1:04 or something like that, but it could be that we want to pass this over so it can say you know, you are the winner or computer's the winner.
1:10 We'll have another way to keep track of that actually. So, we're going to find a winner. Now, notice, this has got red curlies.
1:15 That means find winner doesn't exist yet but it will, it will and then we're just going to go play a round a round like this.
1:25 So we've got to go and create this function. Remember, your function stuff from earlier we can go and type def, this, and do the bits
1:32 or we could just hit alt, enter in PyCharm and say create the function. Don't really like that it puts it at the top
1:39 but it's the safest thing it can do but it's because the way main works it's not necessarily you want main to be the top.
1:45 Okay, so let's just for now return false. We are going to take a while to figure out who the winner is. This is going to be a really elegant solution
1:55 but it's going to take a little bit of thinking through so let's not worry about that now. We're not at that step yet
2:02 but it definitely has uncovered the need for us to be able to, given a board and how it's been played determine, has anybody won this just yet.
2:10 Before we worry about the winners let's figure out how we might just play a round. Now, let's go ahead and run it
2:15 and have a little bit of fun, see what happens. Ah, yes, so I had that backwards. It's going to do this as long as it finds a winner.
2:25 No, you play the game as long as there's not finding a winner. There we go. Play a round, play a round oh my gosh, it's an infinite loop, stop.
2:33 There we go, stop, stop, stop. Well, that part works. We're doing it over and over as you saw and we're checking for a winner.
2:39 Right now we can have a to do implement how we check for a winner.


Talk Python's Mastodon Michael Kennedy's Mastodon