Othello
Download othello.zip.
Craps
%************************************************
%* Welcome to Craps! *
%* Presented by Group K *
%* Shawn Berry, Mikey Zedan, Yu-Shiang Jeng, Yibo Zhao*
%************************************************
clc
clear
%loads dice images
load Dice;
%suppress warnings
warning('off');
%shuffles all rng possibilites
rng('shuffle');
%asks user how much money they have to spend and sets it to funds
funds = input('Please enter how much money you have: ');
%operates while user still has funds
while funds > 0
bet = input('Enter the amount you want to bet: ');
while (bet > funds || bet <= 0)
if (bet > funds)
fprintf('You can''t bet more than your funds\n');
elseif (bet <= 0)
fprintf('You can''t bet zero or less\n');
end
bet = input('Enter the amount you want to bet: ');
end
input('Press enter to roll: ');
%rolls two dice, both between 1 and 6
roll_1 = randi([1 6],[1 2]);
%displays image of dice roll to screen
imshow([Dice{roll_1}]);
%pauses for 1 second
pause(1)
%if the roll adds up to 7 or 11, the user wins
if roll_1(1)+roll_1(2) == 7 || roll_1(1)+roll_1(2) == 11
%displays that the user wins, and adds the bet to player's funds
fprintf('Player wins!\n');
funds = funds + bet;
%spaces result and displays the user's funds
fprintf('\n');
fprintf('Funds remaining: %.2f\n', funds);
continue;
%if the roll adds up to 2,3, or 12 the player loses
elseif roll_1(1)+roll_1(2) == 2 || roll_1(1)+roll_1(2) == 3 || roll_1(1)+roll_1(2) == 12
%displays that the user loses, and subtracts the bet from player's funds
fprintf('Player loses!\n');
funds = funds - bet;
%spaces result and displays the user's funds
fprintf('\n');
fprintf('Funds remaining: %.2f\n', funds);
continue;
end
%tells user to press enter
input('Press enter to roll again: ')
%runs all the time
while true
%rolls two dice, both between 1 and 6
roll_2 = randi([1 6],[1 2]);
%displays image of dice roll to screen
imshow([Dice{roll_2}]);
%pauses for 1 second
pause(1)
%runs if the roll adds up to 7
if roll_2(1)+roll_2(2)== 7
%displays that the user loses, and subtracts bet from user's funds
fprintf('Player loses!\n')
funds = funds - bet;
%breaks out of the loop
break;
%runs if the first and second rolls are the same
elseif roll_2(1)+roll_2(2)== roll_1(1)+roll_1(2)
%displays that the user wins, and adds the bet to player's funds
fprintf('Player wins!\n')
funds = funds + bet;
%breaks out of the loop
break;
end
%press enter to keep playing
input('Press enter to roll again: ')
end
%spaces result and displays the user's funds
fprintf('\n');
fprintf('Funds remaining: %.2f\n', funds);
end