Filter löschen
Filter löschen

Have to make a game, help?

5 Ansichten (letzte 30 Tage)
Torbjørn Herland
Torbjørn Herland am 12 Nov. 2019
Hello, we are a group the had a task of making a game in matlab. It is supposed to have two players, both players start at 0. The game starts with matlab wholenumber between 1000 and 10000 that are saved in a variable S. The players are then supposed to chose a positive number in turn. S is updated and gets a new value every time a player makes a choice. When a player chooses the integer x then g (x) −f (x, S) must be added to this player's score. Every time a score is updated, the program should tell players about the new score. The program should set S equal to x/2^g(x) and inform the players about the new value of S. The game ends when S is equal to 1
Now i've done some parts, but i suck at matlab and having 4 exams to read to so if someone could give me some pointer and maybe an example on how to continue i would be so gratefull!
The main code i have so far is:
player1=0;
player2=0;
S=R();
run R.m
disp(S);
while true
x = input('Enter a number: ', 's');
x = str2double(x);
if ~isnan(x)
break;
else
disp('Only numbers supported');
end
end
player1=player1 + g(x)-f(x,S);
fprintf('\n Thank you \n \n spiller1:');
disp(spiller1)
the R.m:
function [out] = R()
out = randi([1000,10000]);
end
the f(x):
function [z]=f(x,y)
z=abs(x-y);
end
and the g(x)
function [y]=g(x)
i=0;
while true
if (mod(x,2)==0)
i=i+1;
x=(x/2);
else
break
end
end
y=i;
end

Antworten (0)

Kategorien

Mehr zu Strategy & Logic finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by