Skip to content

Instantly share code, notes, and snippets.

View GarthBrooksOfficial's full-sized avatar

GarthBrooksOfficial

View GitHub Profile
function [t1tricks, t2tricks, whoStart,whoRot] = wintrick(playerBoard,trump,orgSuit,t1tricks,t2tricks,whoStart)
%create array that would overlap with the turn order
sprVals = [playerBoard(7,6),playerBoard(6,7),playerBoard(6,5),playerBoard(5,6)];
for(i = 1:4)%find value of each card played
sprVals(i) = cardSort(sprVals(i),trump,orgSuit);
end
rotVals = [0 1 3 2];%array of rotate values to use
%find the rotating value according to which player had the greatest card
% value
whoRot = rotVals(find(sprVals==max(sprVals)));
function [thisSuit, jackVal] = whatSuit(cardVal,trump)
%Finds the suit of the card that was input
thisSuit = blanks(length(cardVal));
jackVal = 0; %Left & right bauer value holder
for(i = 1:length(cardVal))
%sorting of regular cards
if(cardVal(i) < 7)
thisSuit(i) = 's';
elseif(cardVal(i)<13)
thisSuit(i) = 'c';
function [orgTable] = shuffleDeal(carDeck, whoDeal,orgTable)
%shuffle the deck
carDeck = carDeck(randperm(length(carDeck)));
acc = 1;
%deal the cards
for(r = 1:length(orgTable))
for(c = 1:size(orgTable))
if(orgTable(r,c) == 25)
orgTable(r,c) = carDeck(acc);
acc = acc+1;
function orgTable = setTable(noCard, emptCard,emptbCard)
%initializes original table
teamEmptHand = emptCard * ones(1,5);
OppEmptHand = teamEmptHand';
%player labels
%setting up the table requires proper spacing, this was done by manually
%counting(not efficient)
orgTable = ones(11).*noCard;
orgTable(11,5) = 36; orgTable(5,1) = 37; orgTable(1,5) = 38; orgTable(5,11) = 39;
%hands
function [whoTurn,shuffTable] = rotPlay(euch_Scene,shuffTable,coverTable,whoTurn)
%function rotates the table for next player, and updates whose turn it is
shuffTable = rot90(shuffTable);%rotate table
whoTurn = rot90(whoTurn,3);%rotate turn
%makes sure correct player is at the computer
BlankTable = ones(11).*70;
drawScene(euch_Scene,BlankTable)
nexTurn = ['click to switch to player: ' int2str(whoTurn(1))];
nexTurnText = text(500,800,nexTurn);
[~,~,~] = getMouseInput(euch_Scene);
function currTable = putDown(currTable,coverTable,Scene,kitVal)
%function for when the dealer can pick up the card during betting
%make sure dealer is at the table
BlankTable = ones(11).*70;
drawScene(Scene,BlankTable)
dealPut = 'click to switch to the Dealer';
textSwitch = text(500,800,dealPut);
[~,~,~] = getMouseInput(Scene);
delete(textSwitch)
function[playTable, orgSuit] = playCard(playTable,Scene,coverTable,trumpS)
%function plays the card on the table
title('play your card by clicking on it')
orgSuit = 'a';%default for when the first card is being played
tCount = 1;%how many cards have been played
while(tCount <= 4)%until everyone has played
plHand = whatSuit(playTable(10,4:8),trumpS);%get an array of card suits
[r,c,~] = getMouseInput(Scene);%click on card
%figure out if you can play your card
if(isPlayable(orgSuit,playTable(r,c),plHand,trumpS) && coverTable(r,c) ~= 27)
function [p1Val,p2Val] = pCount(p1Val,p2Val,t1Val,t2Val,whoPick)
%function finds out how many points are earned, and adds them to total
%points
if(t1Val>t2Val)%if team 1 wins
p1Val = p1Val + 1;%normal point earned
if(t1Val == 5)%two points for all 5 tricks
p1Val = p1Val + 1;
elseif(mod(whoPick,2) == 0)
p1Val = p1Val + 1;%two points for euchreing opponnent
end
function newTable = nexTrick(playTable, whoRot)
%function finds out who will start the next play phase and displays that
%person accordingly
rotVals = [4,3,2,1];%how many times the table needs to rotate
rotC = rotVals(whoRot+1);%find out which value we'll use
newTable = rot90(playTable,rotC);%rotate the board
%get rid of the played cards
newTable(5:7,5:7) = [70, 26, 70; 26, 70, 26; 70, 26, 70];
function whoKnows = isPlayable(orgSuit,cPlay,tabHand,trumpS)
%find out if a card is playable during playing phase
%false is not playable, true is playable
whoKnows = false;
if(cPlay<25)%make sure it is an actual card
if(isequal(orgSuit,'a'))%if the card is the first one being played
whoKnows = true;
elseif(isequal(orgSuit,whatSuit(cPlay,trumpS)))%does the card follow suit
whoKnows = true;%it does so it can be played
else