Lists & Tic Tac Toe Game - Python 3 Programming Tutorial p.3
Skills:
Prompt Craft80%Advanced Prompting70%Prompt Systems Engineering60%Agent Foundations50%Tool Use & Function Calling50%
Key Takeaways
The video demonstrates the creation of a text-based Tic Tac Toe game using Python 3, utilizing lists to represent the game board and process logic. It covers breaking down complex problems into smaller pieces, using programming to understand numbers, and representing the game map with zeros, ones, and twos, later converting to X's and O's and lines.
Full Transcript
what's going on everybody and welcome to part three of the Python 33.7 to be specific basics tutorial in this video what we're going to be doing is starting our overarching objective for the series which is to create a text-based version of tic-tac-toe which should allow us to cover all the basics we need before we can get the heck out of the basics and start doing things that you personally are interested in so with that let's go ahead and get started so first of all right out of the gate we we know what we want to do we want to make tic-tac-toe we're gonna simplify it by not making any sort of graphical user interface we're going to keep it just text-based so that the the graphical bit is so we can see the game and all that will just happen in the console basically so so that's all so we're gonna keep it there but we still have a lot of questions to answer like you know we know that we want to make tic-tac-toe I think most of us know going into tic-tac-toe how the game works and the rules but how do we make a program know the rules and how do we display it just right how do we take an input from the user to where they want to play all that stuff how do we how do we actually do that so the first thing and honestly this is a this is these questions or this is how you approach any problem obviously tic-tac-toe is a super basic thing but it forces there's actually a lot of complex things associated with even just something as simple as tic-tac-toe so hopefully this approach to solving the problem will make sense to you and you can start to kind of think this way about any problem so when you've got a problem you what you have to do is just break it down into just the mote the smallest pieces that you can just start ticking off those small pieces until finally you've got your finished product so the first thing we want to do is I'm just going to go ahead and clear everything out here and let's just run that clear it up so so with the game to play tic-tac-toe we need to play it on something we need some sort of game visual you know game map so to speak so to do that how do we want to actually visualize the game itself so we could do something like you know somehow visualize a bunch of emptiness and then you know or maybe make the grids like so obviously if you were to draw tic-tac-toe it's like two lines and then two lines that's gonna be kind of hard we would spend a lot of time with the whole ASCII stuff just getting everything to line up just right and depending on which editor someone uses or which consoles someone's using or what their font is that could get hairy really quickly so don't really think I want to do that necessarily so let's just keep it unbelievably basic so let's say let's just say we we're gonna work with zeros ones and twos so zeros will be just the game map so also just a thing to note later on when like we're gonna do things in terms of just using numbers but later if you want it and I totally if anybody is like man that's lame I wanted the two lines if that's you what you should do is when we're done here add the two lines to the representation because it's totally possible it's just not necessary but later you can convert everything you can convert zeros to be spaces then you could convert you know the ones and twos to actually be X's and O's and then you could convert every you know all the things in between you could use logic to create the two lines and stuff so I definitely encourage anybody who wants to to take that extra step so to start we're going to just use lists and we're going to use a list of lists to represent our game board and to to process all of our logic because at the end of the day programming likes to understand numbers not so much the visual representation as we go on we could we can learn to do things like image processing and image analysis and even machine learning and stuff to to learn what a you know visually a tic-tac-toe map means but chances are you're not looking to get that complex here we're just trying to learn the basics so so let's get started so let's just say we've got a game so I'm gonna do the game variable here and we're going to say game equals and then we could make it a tuple right so we could say zero zero zero so we could do something like that right and then maybe come down and then somehow like kind of cheat our way through here and zero zero zero and don't forget this comma that would be a syntax error yikes so we could try to do something like that but even that's gonna be a problem at least without our parentheses so we could continue like this so let's just copy in paste now what would be the issue with our game like this because we could print game now there's gonna be two major issues one you should know out of the gate immediately as we talked about in the last tutorial but there's actually two issues let's print it out and the second issue is going to be glaring here's the second issue the game isn't represented like this it's represented in just a flat because that newline is just white space it doesn't mean anything to our programming language unless it's a code block so so right now it's just a what we would call them programming just it's just a flat tuple here so so what could we do but also it's a tuple so it's immutable we can't change it over time so we don't want that so then what we'd have to do is like do some redefinition and stuff it would be just a huge mess so instead we're going to use lists so we can convert this to a list really simply from parentheses to square braces here boom now it's a list we can run that again we see okay it's a list we can even run type game and we'll see ah it's a list so but the problem is of course we have the issue of it's all flat when we try to display it an event we still want people to at least understand what's happening in the game so I'm gonna instead convert this to a list of lists so now we've got this first row and now we've got the second row and then we'll add a third row that's getting angry because we don't have a bracket here done now if we were to print game we can see here okay they're separated but they're still they're not they're not like our new line so what could we do to solve that problem what we learned it in the last tutorial we can just iterate over game to display it all pretty like so what we could say is four four row in game prints row and now let me remove game here since that made it kind of confusing and now that's starting to look like a 3x3 grid that we could begin to place things on and all that so so now we're starting to see okay the game map is coming together now let's say you're a user and you wanted to play on this game map the next thing that we have to do is figure out how can we get people to actually say okay I want to play this spot here because again like I said in the very beginning you know I always thought all programs were these graphical user interfaces but in reality they're not and so without getting some pretty complex code we're not gonna get like a mouse that we're gonna be like I want to move here and so we need to let the user input in some way where do they want to go but in order to do that the user has to know okay what do I call this so in general we might have like some numbers or some letters and those say I want to move to 1a or something like that and as long as we do something like that we can keep it totally text-based so in the next tutorial that's what we're gonna start working on is okay we know how to iterate over this but now how do we like as we iterate just represent and show you know 0 1 2 and ABC or something like that so the user could just easily type in okay I want to move to such-and-such location and then we could process that and actually you know make a mark there and begin to analyze did they make a you know fully diagonal or horizontal or vertical and all that so anyways that's what we're gonna do in the next tutorial questions comments concerns leaving below or join the discord otherwise I will see you guys in another video
Original Description
Learning about lists and beginning our Tic Tac Toe project!
Playlist: https://www.youtube.com/playlist?list=PLQVvvaa0QuDeAams7fkdcwOGBpGdHpXln
#python #programming #tutorial
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: Prompt Craft
View skill →
🎓
Tutor Explanation
DeepCamp AI