Wrapping up TicTacToe - Python 3 Programming Tutorial p.14

preview_player
Показать описание
Welcome to part 14 of the Python 3 basics series. Things are definitely cleaning up, we just have a few more things to conquer here. We need to stop players from playing over one another, we need to fix repetition in the win function, we need to fix the scalability of the column numbers, and, finally, we need to actually return winners and either quit/restart the game!

#python #programming #tutorial
Рекомендации по теме
Комментарии
Автор

I spent 14 hrs going thru the entire list of tutorials and I usually have a short attention span, but the way you taught is so damn captivating and easy. So thank you so much!

crimsonsongbird
Автор

4:07 That evil laugh!🤣👹Although it was for short period.  I expected it to be longer🤣

ArshdeepSingh-nmtt
Автор

30:38 is a beautiful laugh. Thank you, you legitimately made me smile and laugh

southgecko
Автор

You can also chain methods to generate a board of variable size in numpy:
for i in np.zeros((3, 3).astype(int).tolist():
print(i)
would give a list of integer 0s within a list, just like we are trying to make.

nobelphoenix
Автор

I know it's been a couple of months since you uploaded this video but i want to thank you for these tutorials. You really helped me to understand Python basics and I also learned a lot about proper syntax. I am really thankful for your efforts.


If it's about the game, it still needs some corrections. Firstly, when you make the game size different than 3, you have to change the question about column and row. I think it should be something like:


column_choice = int(input(f" What column do you want to play? {[i for i in range(game_size)]}: "))
row_choice = int(input(f" What row do you want to play? {[i for i in range(game_size)]}: "))



Aand also it doesn't look pretty when the game board prints twice. But i didn't figure it out how to repair it yet :D

heniekhenkowski
Автор

I have attempted below logic for the Tie and it is working.
check = [ ]
for row in game:
if(row.count(0)>0):
check.append(row)
if len(check)==0:
print('Match Tied!')
return True

Note: It should be the last check in the win() function.

VigneshKiswanth
Автор

Small mistake though, win doesn’t actually use the current_game that it’s being passed. Rather it uses the “global” game board. This could cause issues later down the road. Love the content! Cheers!

Indemere
Автор

One way you could do the presentation is using the numbers 1-9


1 | 2 | 3

4 | 5 | 6

7 | 8 | 9


and to input you could use something like:
def place_at(pos, to_place):
pos -= 1
positions[pos//3][pos%3] = to_place


where 'pos' is the number you want to place 'x' or 'o'. to_place is 'x' or 'o'


Only problem is that it isn't dynamic, but it can definitely won't be that hard, just change the number you divide.

ChettahZpeed
Автор

Thank you! These have been very useful. I'll likely be coming back for review and solidification of some concepts that flew over my head as a beginnner

ohimark
Автор

If you annoyed of 2 game boards appear, delete "print(row)", in my code it is in line 14

nowybopes
Автор

i wish things were explained more in this episode and the last, struggling to follow what's being showed. wish there was a follow up showing how this can be optimized, otherwise enjoyed the rest of the playlist

Slayerkey
Автор

since the numbers 10+ take more space i just had some issues with the look of tic tac toe games that are more than 10 by 10 :)


really enjoyed this series so far
so thx a lot :)

finnjohannsen
Автор

Thanks a lot sentdex for the course I learned a lot it is a great course and also you teach great habits and I manage to get the basics !!!

danielmontejo
Автор

game = [ [0, ] * game_size for i in range(game_size) ] does the same thing
btw, thank you very much for this series, it helped a lot ! :)

Dukee
Автор

Hey I tested a bit and included the horizontal / vertical winning condition with a dictionary. i included a second, hard coded variable in the all_same function that corresponds with the key of the dictionary and returns the value to the f string.

dictionaries = {1: "horizontal", 2: "vertikal", 3: "diagonal"}
type = []

def all_same(l, type):
if l.count(l[0]) == len(l) and l[0] != 0:
print(f"Spieler {aktueller_spieler} hat {dictionaries[type]} gewonnen")
return True
else:
return False

for row in tik_tak_toe:
if all_same(row, 1):
return True


I'm pretty sure this is a very rudimentary way and actually isn't as I intended in the beginning but it works.
Thanks for the tutorial and greetings from germany!

PS: i'm open for more elegant solutions

MyvilMe
Автор

Great series, I made! Thanks so much for taking the time to teaching me, I can now code in python, so happy : 😀

barrjohnm
Автор

Okay, but how about a situation when every element of matrix is already occupied and no one won? It's gonna be a neverending loop as 'game_won' still equals 'False' .
Shouldn't we introduce another variable to cope with it - like counter and when it equals 'len(game)^2' we change the 'game_won' to 'True' so we can restart our game.

kamilawhocares
Автор

TicTacToe, no a big deal? :) It was a moment, more or less between 13 and 14, when I lost. Finally my code works, but to be honest I need to analyze your code at the end, because three loops (easy) and a few strange variables (hard). Thanks for your tutorial.

sportsman-nw
Автор

Do we need:
game, _ = game_board(game, just_display=True) ?
Could we not just use:
game_board(game, just_display=True) ?? is there a pitfall here?...
Also, good job @sentdex

tombaker
Автор

This series gave me CONFIDENCE. Thank you !!!! _/\_

ankurrsaxena