Pls help to write a (java/python/C) code for the game below, and the second pict
ID: 3919573 • Letter: P
Question
Pls help to write a (java/python/C) code for the game below, and the second picture is the hint of the code (yellow words)Hint: Primitive is specific to game, returning the value of a primitive position. A better name is PrimitiveValue, actually. For 1,2,...,10 If given 10 it would return Lose. It is an error to call PrimitiveValue on a non-primitive position. (Here less than 10). Solve is NOT specific to a game, and can be called with any position, and it walks the tree and calculates and returns the value of the position it is given.
(gives all available moves for this position e.g. genmoves(6) = {1,2} ) Strong Solving Example: 1,2,...,10 Rules (on your turn): Running total = 0 Rules (on your turn): Add 1 or 2 to running total Goal Be the FIRST to get to 10 . Example a Ana: "2 to make it 2 a Bob: "1 to make it 3" a Ana: "2 to make it 5 7 ducks (out of 10) Bob: "2 to make it 7" ? photo a Ana: "1 to make it 8" Bob: "2 to make it 10" I WIN!
Explanation / Answer
package abc;
public class StrongSolution {
static int runttl = 0; // For keeping track of progress
static int predict(int r)
{
int c = 0;
for(int i = r; i < 10;i++)
{
c ++ ;
}
if(c % 2 == 0)
return 1;
else
return 2;
}
/* This function predicts what value to add next time to runttl /*
public static void main(String[] args)
{
int i = 0;
while(runttl < 10)
{
int p = predict(runttl); //for getting to know who is winning
if(p == 1) // for slowing down opponent
runttl += 1;
else
runttl += 2;
i++;
System.out.println(runttl);
}
if(i % 2 == 0)
System.out.println("ANA WINS");
else
System.out.println("BOB WINS");
}
}