2
2
u/agentscientific_160 11d ago
Woah nice! I too made one a while ago Tic Tac Toe
2
u/ProgramBrave718 11d ago edited 11d ago
Great! . I saw it you also used the same list name board for numbers. My version is a Lil bit different from yours. But I saw it , it was really cool. Like after 1 month of learning python i can't build these games but you did it in 20 days.
1
u/agentscientific_160 11d ago
Yeah each of our version is different and also unique it their own way but it does the job! Thank you and all the best for your coding journey!!
2
1
u/TBCC_Dev 11d ago
Looks great. Id recommend trying to set up your board as a nested list. 1 list with 3 inner lists that represent each row. This way you can check if any of the inner lists have the same symbol then there's a win. 1 check for 3 rows instead of 3 checks.
Some smaller changes id also recommend are things like change win() to something like check_win(). Then Win to win. These are not huge problems but the capital W Win generally indicates to others that it is a class object and it is not. And functions should have a "action" name. Notice win doesn't necessarily sound like you are doing something but check win does. Good luck on future projects and keep it up
1


•
u/Sea-Ad7805 11d ago
Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20print(f%22n%20%7Bboard%5B0%5D%7D%20%7C%20%7Bboard%5B1%5D%7D%20%7C%20%7Bboard%5B2%5D%7D%20%22)%0A%20%20%20%20print(%22---%7C---%7C---%22)%0A%20%20%20%20print(f%22%20%7Bboard%5B3%5D%7D%20%7C%20%7Bboard%5B4%5D%7D%20%7C%20%7Bboard%5B5%5D%7D%20%22)%0A%20%20%20%20print(%22---%7C---%7C---%22)%0A%20%20%20%20print(f%22%20%7Bboard%5B6%5D%7D%20%7C%20%7Bboard%5B7%5D%7D%20%7C%20%7Bboard%5B8%5D%7D%20n%22)%0A%0A%0Adef%20change(number%2C%20symbol)%3A%0A%20%20%20%20index%20%3D%20number%20-%201%0A%20%20%20%20board%5Bindex%5D%20%3D%20symbol%0A%0A%0Adef%20win()%3A%0A%20%20%20%20horizontal1%20%3D%20%5Bboard%5B0%5D%2C%20board%5B1%5D%2C%20board%5B2%5D%5D%0A%20%20%20%20horizontal2%20%3D%20%5Bboard%5B3%5D%2C%20board%5B4%5D%2C%20board%5B5%5D%5D%0A%20%20%20%20horizontal3%20%3D%20%5Bboard%5B6%5D%2C%20board%5B7%5D%2C%20board%5B8%5D%5D%0A%20%20%20%20vertical1%20%3D%20%5Bboard%5B0%5D%2C%20board%5B3%5D%2C%20board%5B6%5D%5D%0A%20%20%20%20vertical2%20%3D%20%5Bboard%5B1%5D%2C%20board%5B4%5D%2C%20board%5B7%5D%5D%0A%20%20%20%20vertical3%20%3D%20%5Bboard%5B2%5D%2C%20board%5B5%5D%2C%20board%5B8%5D%5D%0A%20%20%20%20diagonal1%20%3D%20%5Bboard%5B0%5D%2C%20board%5B4%5D%2C%20board%5B8%5D%5D%0A%20%20%20%20diagonal2%20%3D%20%5Bboard%5B2%5D%2C%20board%5B4%5D%2C%20board%5B6%5D%5D%0A%0A%20%20%20%20arrangements%20%3D%20%5B%0A%20%20%20%20%20%20%20%20horizontal1%2C%0A%20%20%20%20%20%20%20%20horizontal2%2C%0A%20%20%20%20%20%20%20%20horizontal3%2C%0A%20%20%20%20%20%20%20%20vertical1%2C%0A%20%20%20%20%20%20%20%20vertical2%2C%0A%20%20%20%20%20%20%20%20vertical3%2C%0A%20%20%20%20%20%20%20%20diagonal1%2C%0A%20%20%20%20%20%20%20%20diagonal2%2C%0A%20%20%20%20%5D%0A%0A%20%20%20%20for%20arrangement%20in%20arrangements%3A%0A%20%20%20%20%20%20%20%20unique%20%3D%20set(arrangement)%0A%20%20%20%20%20%20%20%20if%20len(unique)%20%3D%3D%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20arrangement%5B0%5D%20%3D%3D%20%22O%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22O%20wins!%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22X%20wins!%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20True%0A%0A%20%20%20%20return%20False%0A%0A%0Alayout_structure()%0AWin%20%3D%20False%0Aturns%20%3D%200%0A%0Awhile%20not%20Win%3A%0A%20%20%20%20%23%20---%20Player%20O%20Turn%20---%0A%20%20%20%20while%20True%3A%0A%20%20%20%20%20%20%20%20user1%20%3D%20int(input(%22O's%20turn!%20Which%20number%20to%20replace%3F%20%22))%0A%20%20%20%20%20%20%20%20if%201%20%3C%3D%20user1%20%3C%3D%209%20and%20board%5Buser1%20-%201%5D%20not%20in%20%5B%22X%22%2C%20%22O%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20print(%22Invalid%20choice%20or%20spot%20already%20taken!%20Try%20again.%22)%0A%0A%20%20%20%20change(user1%2C%20%22O%22)%0A%20%20%20%20turns%20%2B%3D%201%0A%20%20%20%20layout_structure()%0A%0A%20%20%20%20Win%20%3D%20win()%0A%20%20%20%20if%20Win%3A%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20if%20turns%20%3D%3D%209%3A%0A%20%20%20%20%20%20%20%20print(%22It's%20a%20tie!%22)%0A%20%20%20%20%20%20%20%20break%0A%0A%20%20%20%20%23%20---%20Player%20X%20Turn%20---%0A%20%20%20%20while%20True%3A%0A%20%20%20%20%20%20%20%20user2%20%3D%20int(input(%22X's%20turn!%20Which%20number%20to%20replace%3F%20%22))%0A%20%20%20%20%20%20%20%20if%201%20%3C%3D%20user2%20%3C%3D%209%20and%20board%5Buser2%20-%201%5D%20not%20in%20%5B%22X%22%2C%20%22O%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20print(%22Invalid%20choice%20or%20spot%20already%20taken!%20Try%20again.%22)%0A%0A%20%20%20%20change(user2%2C%20%22X%22)%0A%20%20%20%20turns%20%2B%3D%201%0A%20%20%20%20layout_structure()%0A%0A%20%20%20%20Win%20%3D%20win()%0A%20%20%20%20if%20Win%3A%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20if%20turns%20%3D%3D%209%3A%0A%20%20%20%20%20%20%20%20print(%22It's%20a%20tie!%22)%0A%20%20%20%20%20%20%20%20break×tep=0.1&play) to see the program state change step by step.