Python Forum
Coding Python to make a game similar to Tic-Tac-Toe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Python to make a game similar to Tic-Tac-Toe
#1
Hello all, so my Professor has set an assignment for me to complete. Here are the details on it:

He wants me to produce a game with tiles numbered 1 to N = 9 inclusive. Two players take turns, picking one tile at a time, and the first to make T = 15 from q = 3 tiles is the winner. If neither can make T, the game is a draw.

I must produce functions (requirements described below) which accept a list of integers n (1 ≤ n ≤ N) representing the tiles picked so far, and returns a valid tile (i.e not already picked).
The layout of the function is illustrated by agent_cat, which first makes a list of remaining tiles and then picks one at random:

q,N,T = 3,9,15
from random import choice
def agent_cat(nums):
remaining = list()
for n in range(1,N+1):
if not n in nums:
remaining.append(n)
return choice(remaining)

player1: Valid code which defeats "cat" strategy most of the time.

Extensive look-up tables, or accessing any external resource, is not allowed.
Thinking time limited to 10s per move. Please use the function names specified.


Now, I don't want the answers - I don't want it at all.
I am just looking for advice on how I could tackle this type of challenge. Like, where to start really... Hoping that the advice I get from here will act as a domino effect for me figuring out how to tackle this assignment.

Thank you for all the help in advance guys!
Reply
#2
You have to beat something picking numbers at random. Can you beat a tic-tac-toe player who plays at random? Because this game is just tic-tac-toe using a 3x3 magic square as a game board.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Yea, so you literally have to code a strategy where you would beat the agent_cat, who picks randomly, every time.
Reply
#4
This sounds a bit different, not quite a typical tic tac toe. The strategy I would choose would be two steps:
1. If the tile that would make your sum 15 is available, pick it and win.
2. Otherwise, pick the tile that would block your opponent from getting 15.
Example, opponent picks 9. You pick 6. Opponent picks 4 (total=13). You pick 2. Opponent picks 5 and is now over 15. You have 8, so you pick 7 and win.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Assignment to make a multiple choice game blacklight 1 2,172 Aug-14-2020, 02:37 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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