FAQ: Minimax - The Minimax Function

This community-built FAQ covers the “The Minimax Function” exercise from the lesson “Minimax”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise The Minimax Function

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Why does it only tick 8 with ‘X’?
Becuase the outcome of available_moves(x_winning) is [2, 4, 6, 7, 8], doesn’t it have to tick all these 5 numbers with X?

about the variables being pointing to a memory. -
why does it not happen when i do this ?
x= 5
y = x
y = 10
print(x)
print(y)

the output comes out to be 5 and 10. if variable y is set as equal to x, it is merely pointing to a location where value of x is saved! then after changing the value of y, which is at the same location of x, why doesn’t it change the value of x?

If this is so, why copying my_board too new_board has to be done using deepcopy function ?

1 Like

Have a look at this answer for a little info-

You’ll find a few arguments over the semantics but Python doesn’t use variables as pointers, they are references (or names) to objects. Pass by assignment where assignment creates a new reference is how the docs refer to it. You may have to search around a bit for an answer that makes sense to you.

For your example your first statement `x = 5` assigns `x` a reference to an integer object. When you use the statement `y = x` you assign `y` to reference the same object as `x` references. When you execute the next statement `y = 10` you have a new integer object and you assign `y` to reference it.

These objects are not altered at any point in this code. All you’ve done is changed what object y references (for ease people sometimes refer to this as just changing the labels assigned to particular objects, or even making an analogy with post-it notes being taken off one object and stuck on another). Even if you now reassigned `x`, e.g. `x = 0` you still haven’t altered the first integer object (`5`).

For most objects, a reference count of zero would make them open to garbage collection but Python permanently keeps a certain number of integer objects in memory (-5 to 256 I believe). In most cases you can just assume the object will be freed up in memory.

Can you see why deepcopy might be useful then. We do not want to copy the references. We want to copy the objects themselves.

2 Likes