Yeeeeah Bitch!
#1
Posted 14 May 2004 - 01:59 AM
#! /bin/perl
#
# Csa.pl - Critical Section Avoidance Project
# CS 431 Spring '04
# Requires Csa.dat containing lock/unlock algorithms
#
open(SOLUTIONS, "<./Csa.dat")
or die "Cannot open $!";
chomp(@solutions = <SOLUTIONS>);
# seed the random number generator from the clock
srand;
# enter solution loop
for($s = 1; shift(@solutions) =~ /solution*/; $s++) {
# clear memory and load up a solution
@memory = ();
shift(@solutions);
for($x = 10; $solutions[0] =~ /^[0-9]/; $x++) {
$memory[$x] = shift(@solutions);
}
shift(@solutions);
shift(@solutions);
for($x = 60; $solutions[0] =~ /^[0-9]/; $x++) {
$memory[$x] = shift(@solutions);
}
shift(@solutions);
print("SOLUTION $s\n");
# enter trial loop for 50 runs
$exclusive = 1;
$bounded = 1;
for($run = 1; $run <= 50; $run++) {
$counter = 0;
$pc1 = 10;
$pc2 = 60;
$acc1 = 0;
$acc2 = 0;
$memory[0] = 0; # flag/flag1
$memory[1] = 0; # flag2
$memory[2] = 1; # turn
$memory[3] = 5; # size
# enter process scheduler loop
while( ($pc1 > 0 || $pc2 > 0) &&
($counter < 1000) ) {
# increment counter and pick a process
$counter++;
if($pc1 == -1) {
$proc = 2;
} elsif($pc2 == -1) {
$proc = 1;
} else {
$proc = int(rand 2) + 1;
}
# fetch an instruction, increment pc, and decode
if($proc == 1) {
@encoded = split / /, $memory[$pc1];
$pc1++;
} else {
@encoded = split / /, $memory[$pc2];
$pc2++;
}
$instruction = $encoded[0];
$value = $encoded[1];
# execute!
if($instruction == 0) { # STOP
if($proc == 1) {
$pc1 = -1;
} else {
$pc2 = -1;
}
} elsif($instruction == 1) { # STORE
if($proc == 1) {
$memory[$value] = $acc1;
} else {
$memory[$value] = $acc2;
}
} elsif($instruction == 2) { # LOAD CONST
if($proc == 1) {
$acc1 = $value;
} else {
$acc2 = $value;
}
} elsif($instruction == 3) { # LOAD LOC
if($proc == 1) {
$acc1 = $memory[$value];
} else {
$acc2 = $memory[$value];
}
} elsif($instruction == 4) { # ADD
if($proc == 1) {
$acc1 += $value;
} else {
$acc2 += $value;
}
} elsif($instruction == 5) { # SUBTRACT
if($proc == 1) {
$acc1 -= $value;
} else {
$acc2 -= $value;
}
} elsif($instruction == 6) { # JUMP
if($proc == 1) {
$pc1 = $value;
} else {
$pc2 = $value;
}
} elsif($instruction == 7) { # COND JUMP
if($proc == 1) {
if($acc1 == 0) {
$pc1 = $value;
}
} else {
if($acc2 == 0) {
$pc2 = $value;
}
}
} elsif($instruction == 8) { # SWAP
if($proc == 1) {
$temp = $acc1;
$acc1 = $memory[$value];
$memory[$value] = $temp;
} else {
$temp = $acc2;
$acc2 = $memory[$value];
$memory[$value] = $temp;
}
}
} # end process scheduler loop
print("\t\tRUN $run\t\tSIZE = $memory[3]\t\tCOUNTER = $counter\n");
if($memory[3] == 6) {
$exclusive = 0;
}
if($counter >= 1000) {
$bounded = 0;
}
} # end trial loop
print("\n");
if($exclusive && $bounded) {
print("\t\t*** CORRECT SOLUTION ***\n\n");
} else {
if(!($exclusive)) {
print("\t\t*** VIOLATE MUTUAL EXCLUSION ***\n");
}
if(!($bounded)) {
print("\t\t*** VIOLATE BOUNDED WAIT ***\n");
}
print("\n");
}
} # end solution loop
#2
Posted 14 May 2004 - 02:27 AM
I hope that gets you an "A".
Not being versed in that particular OS language, for me it drew "zzzzz"s.
[/dazed, confused, tired]
Hopeful,
-Piney-
<!--quoteo(post=209846:date=Feb 5 2009, 06:27 PM:name=boom)--><div class='quotetop'>QUOTE(boom @ Feb 5 2009, 06:27 PM) </div><div class='quotemain'><!--quotec-->
It's to bad you live in hawaii I bet there are not many wars there.Wait what am I saying<b> you live in hawaii you lucky bastard.</b>
<!--QuoteEnd--></div><!--QuoteEEnd-->
#3
Posted 14 May 2004 - 11:45 AM
Strikes a close resemblence to C++.
Doin' coke, drinkin' beers, Drinkin' beers beers beers
Rollin' fatties, Smokin' blunts
Who smokes the blunts? We smoke the blunts
-Jay
#4
Posted 14 May 2004 - 01:28 PM
Perl's syntax is very similar to C.The sad thing is, I found it to be of mild interest...
Strikes a close resemblence to C++.
----- Cut here if you're not into coding -----
There are lots of nifty features about Perl that make programming easier though.
for($x = 60; $solutions[0] =~ /^[0-9]/; $x++) { $memory[$x] = shift(@solutions); }
There are only two things in this fragment that are appreciably different than C.
For one, it duplicates the sed/awk functionality of *NIX shell scripting. The terminal condition of the loop: $solutions[0] =~ /^[0-9]/ is and example of the Perl regexp function. In this case it returns true if the first element of the 'solutions' list (array) starts with a digit. It could be a number or an ascii string that starts with a digit, Perl doesn't care. Very Cool. In fact, this applies to all variables in Perl - I read the contents of that list in as a string and later will manipulate it numerically without having to cast it or transfer it to a new variable.
The shift operator comes from the push, pop, unshift, shift collection which gives you built-in functionality for manipulating lists (arrays) as stacks or queues. Very simple to do typical data structure manipulation. In this case, shift is removing the 0th element of the 'solutions' list, sliding everything else in the list down, and returning the value it just removed. For example:
@stuff = ("hello", 42, 'c'); # list 'stuff' contains the 3 items ("hello", 42, 'c')
$hi = shift(@stuff); # 'stuff' now contains (42, 'c') and 'hi' contains "hello"
push(@stuff, $hi); # 'stuff' now contains (42, 'c', "hello")
Cool language. I like the fact that it always does what I expect a language to do. It's the only language that I can take a 6 month break from and then sit down with my O'Reilly books and write a program like the above in about 5 hours with only about 20 minutes debugging time. Everything else (I have coded in about 10 languages) requires several hours (or more) spent re-familiarizing myself with the odd little quirks and traps that make your code blow up in that particular language.
#5
Posted 14 May 2004 - 01:32 PM
#6
Posted 14 May 2004 - 02:18 PM
#7
Posted 14 May 2004 - 04:56 PM
Doin' coke, drinkin' beers, Drinkin' beers beers beers
Rollin' fatties, Smokin' blunts
Who smokes the blunts? We smoke the blunts
-Jay
#8
Posted 14 May 2004 - 05:47 PM
Tons of people use Perl for everything from little data manipulation scripts to full-fledged extremely robust programs. I know someone who ported the entire DikuMUD codebase to Perl - if it can handle a 30,000 line text-based MMORPG originally written in ANSI C, it can do pretty much anything.
Perl's real strength lies in the ability to quickly and easily write relatively simple programs. If the project requires a dozen programmers, Perl is not the best choice. If the project requires one programmer and it can be written in a day or two, Perl is probably an excellent choice. In between those two extremes, the advantages and disadvantages tend to balance out. It is used a lot in CGI scripting for web back-end stuff. Form mail scripts, forum software, you name it. If you're curious to see an example, Slashdot is written in Perl - you can download the source at slashcode.
That said, you will rarely see a job listing for a Perl programmer. Anybody who does full-time programming for a living probably works in a shop with a bunch of other programmers. Tools for VB, C++, or C# development are generally better at supporting large dev teams working on large projects. The people who use Perl have job descriptions like mine - sys admin, coding, database, and general system integration.
Oh, if anybody is curious, that program emulates a CPU with two accumulators, two program counters, and eight instructions as well as a trivial process scheduler. It's a simulator designed to test critical section avoidance techniques that prevent programs with multiple processes from accessing shared memory at the same time and creating race conditions and data corruption. The data file consists of assembly code implementations of 7 different examples of lock/unlock code. 400-level CS classes are cool but very tiring.
#9
Posted 02 June 2004 - 04:15 PM
So to add to the mass of code already on this thread here is 802 lines of code I wrote.....get this.....for fun! Feel free to run it if you have matlab.
function[]=blackjack(x)
%BLACKJACK v4.1
% The game of BlackJack
% BLACKJACK('p') prompts for initial pot
% BLACKJACK('c') resets the highscore to default
% BLACKJACK('q') activates cheat mode. Bet 999999 to activate cheat.
%
% Programmer : Evan Neblett
% Version history :
% 1.0 Initialization of working base code
% 2.0 Creation of friendly interface
% 2.1 Addition of variable pot
% 2.6 Addition of more extensive rules
% 2.7 Addition of hiscore
% 2.8 Addition of cheat
% 3.0 Scoring system modified
% 3.2 Addition of audio
% 4.0 Addition of cards suites, 5 card rule
% Extreme code modification
% 4.1 Rule modification
%***** INITIAL *****
%CALL CHECK
if nargin < 1
x = 'a';
pot = 1000;
cheatnum = 0;
end
%INPUTS
if x == 'p'
cheatnum = 0;
pot = input('How much money would you like to start with?\n?');
elseif x == 'c'
cheatnum = 0;
pot = 1000;
check = input('Are you sure you want to delete the hiscore file?\n?','s');
if check == 'y'
delete hiscore.mat
disp(['File deleted'])
end
elseif x == 'q'
pot = 1000;
cheatnum = 1;
end
%LOAD HIGHSCORE
if exist('hiscore.mat') == 2;
load hiscore
elseif exist('hiscore.mat') == 0;
highscore = 100;
name = 'MatLab';
when = date;
save hiscore highscore name when
end
%***** MAIN *****
%TITLE
clc
disp([' '])
disp(['********************************************'])
disp(['***************** BLACKJACK ****************'])
disp(['********************************************'])
disp([' ']);
disp([' HIGH SCORE'])
disp([' ',num2str(highscore),' ',name,' ',num2str(when),''])
disp([' '])
disp(['INSTRUCTIONS'])
disp([' I will deal you and I two cards initially.'])
disp([' You have the option to hit or stand in an attempt to come as close to 21 as you can.'])
disp([' You will start off with 1000 dollars to bet with.'])
disp([' To stop playing bid O dollars and your score will be calculated'])
disp([' '])
disp(['Press Enter'])
disp([' '])
%insert tones
%INITIAL VALUES
maxpot = pot;
initpot = pot;
maxwinnings = 0;
maxoccur = 0;
maxpercent = 0;
hands = 0;
potmat(1) = pot;
hand(1) = 0;
init(1) = initpot;
%PLAY REITERATION
while pot > 0;
hands = hands + 1;
disp([' '])
disp(['You now have ',num2str(pot),' dollars.'])
bet = input('Please place your bet for this round.\n?');
if bet == 999999 & cheatnum == 1
cheater = input('How much would you like to add to your pot?\n?');
disp(['CHEATER!!!!'])
pot = pot + cheater;
bet = input('Please place your bet for this round.\n?');
end
if bet == 0;
disp([' '])
quit = input('Would you like to quit while you''re ahead? (y/n)\n?','s');
if quit == 'n'
disp(['Good luck'])
disp(['You now have ',num2str(pot),' dollars.'])
bet = input('Please place your bet for this round.\n?');
elseif quit == 'y'
break
end
end
if isempty(bet) == 0;
if bet > pot;
disp(['You cannot bet more than you have. Setting bet to 1 dollar'])
bet = 1;
end
win=playhand;
if win == 0;
disp([' '])
disp(['You lost ',num2str(bet),' dollars.'])
pot = pot - bet;
elseif win == 1;
disp([' '])
disp(['You made ',num2str(bet),' dollars.'])
pot = pot + bet;
elseif win == 2;
pot = pot;
elseif win == 3;
pot = pot + (1.5 * bet);
end
potmat(hands + 1) = pot;
hand(hands + 1) = hands;
init(hands + 1) = initpot;
if pot > maxpot;
maxpot = pot;
maxwinnings = maxpot - initpot;
maxoccur = hands;
maxpercent = (maxwinnings / initpot) * 100;
end
else
disp(['You must place a bet'])
hands = hands - 1;
end
if pot <= 0;
break
end
end
%FINAL STATS
if pot == 0
disp([' '])
disp(['Sorry, you have run out of money'])
disp(['In ',num2str(hands),' hands, your maximum winnings was ',num2str(maxwinnings),' dollars, which is ',num2str(maxpercent),' percent of your initial pot, occuring in hand ',num2str(maxoccur),''])
disp(['But then you lost it all....You''re in the dog house now.'])
disp(['Your score for this round is 0'])
score = 0;
elseif pot > 0
disp([' '])
disp(['You have quit playing for the time being.'])
disp(['In ',num2str(hands),' hands, your maximum winnings was ',num2str(maxwinnings),' dollars, which is ',num2str(maxpercent),' percent of your initial pot, occuring in hand ',num2str(maxoccur),''])
if pot < initpot
losses = initpot - pot;
disp(['You lost ',num2str(losses),' dollars. Your wifes gonna be mad.'])
score = 0;
disp(['Your score is ',num2str(score),'.'])
elseif pot >= initpot
score = 2 * maxpercent;
disp(['Your score is ',num2str(score),'.'])
end
if score > highscore;
disp(['CONGRADULATIONS!!! YOU HAVE THE NEW HIGH SCORE!!'])
tone(261.625,0.1)
tone(293.664,0.1)
tone(329.627,0.1)
tone(349.228,0.1)
tone(391.995,0.3)
name = input('Please enter you name:\n?','s');
highscore = score;
when = date;
save hiscore highscore name when
end
end
%PLOT HISTORY
figure;
plot(hand,init,'g','LineWidth',3.0)
hold on
plot(hand,potmat,'-ro','LineWidth',3.0,'MarkerEdgeColor','k','MarkerSize',8,'MarkerFaceColor','b')
legend('Initial pot','Winnings and Losses',2)
xlabel('Hand')
ylabel('Pot (Dollars)')
title('Winnings and Losses')
grid
axis xy
%REPLAY INQUIRY AND CREDITS
disp([' '])
if input('Would you like to play again? (y/n)\n?','s')=='y'
if cheatnum == 1;
blackjack('q')
else
blackjack
end
else
clc
disp([' '])
disp([' ********************************'])
disp([' * Thanks for playing *'])
disp([' * Programmer: Evan B Neblett *'])
disp([' * December 13, 2001 *'])
disp([' ********************************'])
end
%***** PLAY FUNCTION *****
function win=playhand()
clc
%GET CARDS
rawcard=zeros(10,1);
for m=1:1:10;
rawcard(m)=getcard;
end
%DUPLICATE CHECK AND REPLACEMENT
for k=1:1:10;
for kk=1:1:10;
for kkk=1:1:(kk-1);
if rawcard(kk) == rawcard(kkk);
rawcard(kkk) = getcard;
for kkkk=1:1:10;
for kkkkk=1:1:10;
for kkkkkk=1:1:(kkkkk-1);
if rawcard(kkkkk) == rawcard(kkk);
rawcard(kkk) = getcard;
end
end
end
end
end
end
end
end
%SUITE DETERMINATION
suite = cell(10,1);
for ii = 1:1:10;
if rawcard(ii) > 200 & rawcard(ii) < 300;
suite{ii,1} = ' Clubs ';
elseif rawcard(ii) > 400 & rawcard(ii) < 500;
suite{ii,1} = ' Hearts ';
elseif rawcard(ii) > 600 & rawcard(ii) < 700;
suite{ii,1} = ' Spades ';
elseif rawcard(ii) > 800 & rawcard(ii) < 900;
suite{ii,1} = ' Dimnds ';
end
end
%FACE VALUE DETERMINATION
card = zeros(10,1);
for iiii = 1:1:10;
if rawcard(iiii) > 200 & rawcard(iiii) < 300;
card(iiii) = rawcard(iiii) - 200;
elseif rawcard(iiii) > 400 & rawcard(iiii) < 500;
card(iiii) = rawcard(iiii) - 400;
elseif rawcard(iiii) > 600 & rawcard(iiii) < 700;
card(iiii) = rawcard(iiii) - 600;
elseif rawcard(iiii) > 800 & rawcard(iiii) < 900;
card(iiii) = rawcard(iiii) - 800;
end
end
%CARD STRING CELL DETERMINATION
printvalue = cell(10,2);
for iii = 1:1:10
if card(iii) == 2
printvalue{iii,1} = ' 2 ';
printvalue{iii,2} = ' 2 ';
elseif card(iii) == 3;
printvalue{iii,1} = ' 3 ';
printvalue{iii,2} = ' 3 ';
elseif card(iii) == 4;
printvalue{iii,1} = ' 4 ';
printvalue{iii,2} = ' 4 ';
elseif card(iii) == 5;
printvalue{iii,1} = ' 5 ';
printvalue{iii,2} = ' 5 ';
elseif card(iii) == 6;
printvalue{iii,1} = ' 6 ';
printvalue{iii,2} = ' 6 ';
elseif card(iii) == 7;
printvalue{iii,1} = ' 7 ';
printvalue{iii,2} = ' 7 ';
elseif card(iii) == 8;
printvalue{iii,1} = ' 8 ';
printvalue{iii,2} = ' 8 ';
elseif card(iii) == 9;
printvalue{iii,1} = ' 9 ';
printvalue{iii,2} = ' 9 ';
elseif card(iii) == 10;
printvalue{iii,1} = ' 10 ';
printvalue{iii,2} = ' 10 ';
elseif card(iii) > 10.1 & card(iii) < 10.3;
printvalue{iii,1} = ' J ';
printvalue{iii,2} = ' J ';
card(iii) = floor(card(iii));
elseif card(iii) > 10.3 & card(iii) < 10.5;
printvalue{iii,1} = ' Q ';
printvalue{iii,2} = ' Q ';
card(iii) = floor(card(iii));
elseif card(iii) > 10.5 & card(iii) < 10.7;
printvalue{iii,1} = ' K ';
printvalue{iii,2} = ' K ';
card(iii) = floor(card(iii));
elseif card(iii) == 11;
printvalue{iii,1} = ' A ';
printvalue{iii,2} = ' A ';
end
end
edge = '''''''''''''''''';
empty = ' ';
%PLAYERS CARDS
playertotal = card(1) + card(3);
if card(3) == 11 & playertotal > 21
card(3) = 1;
end
playertotal = card(1) + card(3);
tone(200,0.1)
cardnumber = 2;
PlayersHand = cell(8,2);
disp(['YOUR CARDS'])
for i=1:1:cardnumber;
PlayersHand{1,i} = edge;
PlayersHand{2,i} = printvalue{(2*i-1),1};
PlayersHand{3,i} = empty;
PlayersHand{4,i} = suite{(2*i-1),1};
PlayersHand{5,i} = empty;
PlayersHand{6,i} = empty;
PlayersHand{7,i} = printvalue{(2*i-1),2};
PlayersHand{8,i} = edge;
end
disp([' '])
disp(PlayersHand)
disp([' '])
disp(['You have ',num2str(playertotal),' '])
if playertotal == 21;
disp(['YOU HAVE BLACKJACK!'])
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.1)
tone(350,0.1)
tone(350,0.1)
tone(500,0.3)
win = 3;
break
else
draw1 = input('Would you like to hit or stand? (h/s)\n?','s');
if draw1 == 'h';
playertotal = card(1) + card(3) + card(5);
if card(5) == 11 & playertotal > 21
card(5) = 1;
elseif card(3) == 11 & playertotal > 21
card(3) = 1;
elseif card(1) == 11 & playertotal > 21
card(1) = 1;
end
playertotal = card(1) + card(3) + card(5);
tone(200,0.1)
cardnumber = 3;
PlayersHand = cell(8,3);
for i=1:1:cardnumber;
PlayersHand{1,i} = edge;
PlayersHand{2,i} = printvalue{(2*i-1),1};
PlayersHand{3,i} = empty;
PlayersHand{4,i} = suite{(2*i-1),1};
PlayersHand{5,i} = empty;
PlayersHand{6,i} = empty;
PlayersHand{7,i} = printvalue{(2*i-1),2};
PlayersHand{8,i} = edge;
end
disp([' '])
disp(PlayersHand)
disp([' '])
disp(['You have ',num2str(playertotal),' '])
if playertotal > 21;
disp(['*****************'])
disp(['* YOU BUST! *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
else
draw2 = input('Would you like to hit or stand? (h/s)\n?','s');
if draw2 == 'h'
playertotal = card(1) + card(3) + card(5) + card(7);
if card(7) == 11 & playertotal > 21
card(7) = 1;
elseif card(5) == 11 & playertotal > 21
card(5) = 1;
elseif card(3) == 11 & playertotal > 21
card(3) = 1;
elseif card(1) == 11 & playertotal > 21
card(1) = 1;
end
playertotal = card(1) + card(3) + card(5) + card(7);
tone(200,0.1)
cardnumber = 4;
PlayersHand = cell(8,4);
for i=1:1:cardnumber;
PlayersHand{1,i} = edge;
PlayersHand{2,i} = printvalue{(2*i-1),1};
PlayersHand{3,i} = empty;
PlayersHand{4,i} = suite{(2*i-1),1};
PlayersHand{5,i} = empty;
PlayersHand{6,i} = empty;
PlayersHand{7,i} = printvalue{(2*i-1),2};
PlayersHand{8,i} = edge;
end
disp([' '])
disp(PlayersHand)
disp([' '])
disp(['You have ',num2str(playertotal),' '])
if playertotal > 21;
disp(['*****************'])
disp(['* YOU BUST! *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
else
draw3 = input('Would you like to hit or stand? (h/s)\n?','s');
if draw3 == 'h'
playertotal = card(1) + card(3) + card(5) + card(7) + card(9);
if card(9) == 11 & playertotal > 21
card(9) = 1;
elseif card(7) == 11 & playertotal > 21
card(7) = 1;
elseif card(5) == 11 & playertotal > 21
card(5) = 1;
elseif card(3) == 11 & playertotal > 21
card(3) = 1;
elseif card(1) == 11 & playertotal > 21
card(1) = 1;
end
playertotal = card(1) + card(3) + card(5) + card(7) + card(9);
tone(200,0.1)
cardnumber = 5;
PlayersHand = cell(8,5);
for i=1:1:cardnumber;
PlayersHand{1,i} = edge;
PlayersHand{2,i} = printvalue{(2*i-1),1};
PlayersHand{3,i} = empty;
PlayersHand{4,i} = suite{(2*i-1),1};
PlayersHand{5,i} = empty;
PlayersHand{6,i} = empty;
PlayersHand{7,i} = printvalue{(2*i-1),2};
PlayersHand{8,i} = edge;
end
disp([' '])
disp(PlayersHand)
disp([' '])
disp(['You have ',num2str(playertotal),' '])
if playertotal > 21;
disp(['*****************'])
disp(['* YOU BUST! *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif playertotal <= 21;
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.15)
win = 1;
break
end
elseif draw3 == 's'
playertotal = card(1) + card(3) + card(5) + card(7);
end
end
elseif draw2 == 's'
playertotal = card(1) + card(3) + card(5);
end
end
elseif draw1 == 's';
playertotal = card(1) + card(3);
end
end
%DEALERS CARDS
if playertotal <= 21;
dealertotal = card(2) + card(4);
if card(4) == 11 & dealertotal > 21
card(4) = 1;
end
dealertotal = card(2) + card(4);
tone(200,0.1)
disp([' '])
disp([' '])
disp(['DEALER''S CARDS'])
cardnumber = 2;
DealersHand = cell(8,2);
for jj=1:1:cardnumber;
DealersHand{1,jj} = edge;
DealersHand{2,jj} = printvalue{(2*jj),1};
DealersHand{3,jj} = empty;
DealersHand{4,jj} = suite{(2*jj),1};
DealersHand{5,jj} = empty;
DealersHand{6,jj} = empty;
DealersHand{7,jj} = printvalue{(2*jj),2};
DealersHand{8,jj} = edge;
end
disp([' '])
disp(DealersHand)
disp([' '])
disp(['Dealer has ',num2str(dealertotal),''])
if dealertotal > playertotal & dealertotal <= 21
disp(['*****************'])
disp(['* DEALER WINS *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif dealertotal < playertotal & dealertotal > 17
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal >= 17 & dealertotal <=21
disp(['Dealer must stand'])
if dealertotal > playertotal & dealertotal <= 21
disp(['*****************'])
disp(['* DEALER WINS *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif dealertotal < playertotal
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal == playertotal
disp(['THE ROUND IS A DRAW'])
win = 2;
end
elseif dealertotal < 17
dealertotal = card(2) + card(4) + card(6);
if card(6) == 11 & dealertotal > 21
card(6) = 1;
elseif card(4) == 11 & dealertotal > 21
card(4) = 1;
elseif card(2) == 11 & dealertotal > 21
card(2) = 1;
end
dealertotal = card(2) + card(4) + card(6);
tone(200,0.1)
disp(['Dealer must take a hit'])
disp([' '])
cardnumber = 3;
DealersHand = cell(8,3);
for jj=1:1:cardnumber;
DealersHand{1,jj} = edge;
DealersHand{2,jj} = printvalue{(2*jj),1};
DealersHand{3,jj} = empty;
DealersHand{4,jj} = suite{(2*jj),1};
DealersHand{5,jj} = empty;
DealersHand{6,jj} = empty;
DealersHand{7,jj} = printvalue{(2*jj),2};
DealersHand{8,jj} = edge;
end
disp([' '])
disp(DealersHand)
disp([' '])
disp(['Dealer has ',num2str(dealertotal),''])
if dealertotal == playertotal
disp(['THE ROUND IS A DRAW'])
win = 2;
elseif dealertotal > 21
disp(['DEALER BUSTS!'])
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal >= 17 & dealertotal <=21
disp(['Dealer must stand'])
if dealertotal > playertotal & dealertotal <= 21
disp(['*****************'])
disp(['* DEALER WINS *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif dealertotal < playertotal
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal == playertotal
disp(['THE ROUND IS A DRAW'])
win = 2;
end
elseif dealertotal < 17
dealertotal = card(2) + card(4) + card(6) + card(8);
if card(8) == 11 & dealertotal > 21
card(8) = 1;
elseif card(6) == 11 & dealertotal > 21
card(6) = 1;
elseif card(4) == 11 & dealertotal > 21
card(4) = 1;
elseif card(2) == 11 & dealertotal > 21
card(2) = 1;
end
dealertotal = card(2) + card(4) + card(6) + card(8);
tone(200,0.1)
disp(['Dealer must take another hit.'])
disp([' '])
cardnumber = 4;
DealersHand = cell(8,4);
for jj=1:1:cardnumber;
DealersHand{1,jj} = edge;
DealersHand{2,jj} = printvalue{(2*jj),1};
DealersHand{3,jj} = empty;
DealersHand{4,jj} = suite{(2*jj),1};
DealersHand{5,jj} = empty;
DealersHand{6,jj} = empty;
DealersHand{7,jj} = printvalue{(2*jj),2};
DealersHand{8,jj} = edge;
end
disp([' '])
disp(DealersHand)
disp([' '])
disp(['Dealer has ',num2str(dealertotal),''])
if dealertotal == playertotal
disp(['THE ROUND IS A DRAW'])
win = 2;
elseif dealertotal > playertotal & dealertotal <= 21
disp(['*****************'])
disp(['* DEALER WINS *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif dealertotal > 21
disp(['DEALER BUSTS!'])
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win=1;
elseif dealertotal >= 17 & dealertotal <=21
disp(['Dealer must stand'])
if dealertotal > playertotal & dealertotal <= 21
disp(['*****************'])
disp(['* DEALER WINS *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif dealertotal < playertotal
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal == playertotal
disp(['THE ROUND IS A DRAW'])
win = 2;
end
elseif dealertotal < 17
dealertotal = card(2) + card(4) + card(6) + card(8) + card(10);
if card(10) == 11 & dealertotal > 21
card(10) = 1;
elseif card(8) == 11 & dealertotal > 21
card(8) = 1;
elseif card(6) == 11 & dealertotal > 21
card(6) = 1;
elseif card(4) == 11 & dealertotal > 21
card(4) = 1;
elseif card(2) == 11 & dealertotal > 21
card(2) = 1;
end
dealertotal = card(2) + card(4) + card(6) + card(8) + card(10);
tone(200,0.1)
disp(['Dealer must take another hit.'])
disp([' '])
cardnumber = 5;
DealersHand = cell(8,5);
for jj=1:1:cardnumber;
DealersHand{1,jj} = edge;
DealersHand{2,jj} = printvalue{(2*jj),1};
DealersHand{3,jj} = empty;
DealersHand{4,jj} = suite{(2*jj),1};
DealersHand{5,jj} = empty;
DealersHand{6,jj} = empty;
DealersHand{7,jj} = printvalue{(2*jj),2};
DealersHand{8,jj} = edge;
end
disp([' '])
disp(DealersHand)
disp([' '])
disp(['Dealer has ',num2str(dealertotal),''])
if dealertotal < playertotal
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal == playertotal
disp(['THE ROUND IS A DRAW'])
win = 2;
elseif dealertotal > playertotal & dealertotal <= 21
disp(['*****************'])
disp(['* DEALER WINS *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif dealertotal > 21
disp(['DEALER BUSTS!'])
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal >= 17 & dealertotal <=21
disp(['Dealer must stand'])
if dealertotal > playertotal & dealertotal <= 21
disp(['*****************'])
disp(['* DEALER WINS *'])
disp(['*****************'])
tone(80,0.15)
win = 0;
elseif dealertotal < playertotal
disp(['*****************'])
disp(['* YOU WIN! *'])
disp(['*****************'])
tone(350,0.2)
win = 1;
elseif dealertotal == playertotal
disp(['THE ROUND IS A DRAW'])
win = 2;
end
end
end
end
end
end
%***INTERNAL FUNCTIONS***
%CARD GENERATOR
function card=getcard()
value = getvalue;
suite = getsuite;
card = value + suite;
%FACE VALUE GENERATOR
function value=getvalue()
switch fix(13 * rand);
case 0, value = 2;
case 1, value = 3;
case 2, value = 4;
case 3, value = 5;
case 4, value = 6;
case 5, value = 7;
case 6, value = 8;
case 7, value = 9;
case 8, value = 10;
case 9, value = 10.2;
case 10, value = 10.4;
case 11, value = 10.6;
otherwise, value = 11;
end
%SUITE GENERATOR
function suite=getsuite()
switch fix(4 * rand);
case 0, suite = 200;
case 1, suite = 400;
case 2, suite = 600;
otherwise, suite = 800;
end
%TONE GENERATOR
function[]=tone(w,l)
rate = 22050;
t = [0:1/rate:l];
wave = sin(2*pi*w*t);
sound(wave, rate)
pause(l)
CXWQ, if I've pissed you off by adding a 850 line post, then feel free to edit or delete it. I'll completely understand
.
#10
Posted 02 June 2004 - 05:19 PM
This all is a bit confusing. I should ask my brother about this. He'll give me the gist of it. After all, he does this for work. It seems quite neat. I may have to get into this, just to impress friends and stuff. This probably doesn't mean anything from a firearms recognizer*, but that work is pretty damn good!
*I can identify and classify about 250 firearms, not that great, but good enough that teachers come to me. I'm not obsessed, it's just that I needed to prove a few people wrong, so I got into it.
#11
Posted 02 June 2004 - 05:55 PM
You need a girlfriend.** Ultra Snip **
Your m4d 1337 programming 5k1LLz amaze me.
But nobody can talk 1337 as well as I!
I @m +He B3S+ FucK1n9 l33+ 5Pe4KER 1N +H3 EN+Ir3 n3rF inTErNeT cOMMUNity, 81+ChE$!
Edited by Grinch, 02 June 2004 - 05:56 PM.
#12
Posted 02 June 2004 - 07:44 PM
|.......|...........................|<............|......................................| \
Edited by crankymonky, 02 June 2004 - 07:49 PM.
#13
Posted 02 June 2004 - 08:14 PM
I`m actually engaged and getting married on July 3rd....You need a girlfriend.
#14
Posted 02 June 2004 - 08:33 PM
Proof that there is hope for all geeks... Or at least engineers.I`m actually engaged and getting married on July 3rd....
Hope all goes to plan, Bolt. Making a pressurized garter launcher?
- Death
#15
Posted 02 June 2004 - 08:39 PM
That's a damn good idea......!Making a pressurized garter launcher?
#16
Posted 03 June 2004 - 01:47 PM
#17
Posted 03 June 2004 - 03:02 PM
Congrats!I`m actually engaged and getting married on July 3rd....
I have not the slightist idea what this topic means.
Congrats!
#18
Posted 04 June 2004 - 08:42 AM
It's 11:59 here on the left coast and I just finished my OS project and granted access to my prof 3 minutes before the 23:55 deadline
Congrats!
I love stealing thoughts and ideas, especially the ones that are legal to steal...
#19
Posted 05 June 2004 - 07:51 AM
eg
[QUOTE="Witty comment"] Lopes Ipsum Quote Blah Blah[/QUOTE]???
And, in keeping in the theme, if you understood that:
Congrats!
Edited by taita_cakes, 05 June 2004 - 07:56 AM.
#20
Posted 05 June 2004 - 09:21 AM
(QUOTE=9/16 n00b) ...text here... (/QUOTE)
But with brackets instead of parenthesis.
~Vintage
Edit: Cxwq, should I learn Perl, or C++ first? I already know the basics of C++, but not enough to compile any graphical programs.
Edited by Vintage, 05 June 2004 - 09:28 AM.
~Al Capone
#21
Posted 06 June 2004 - 04:55 AM
Yes, in order to add a name (or really anything) to your quotes, you use the format:
(QUOTE=9/16 n00b) ...text here... (/QUOTE)
But with brackets instead of parenthesis.
Thanks mate, your a champion, i get it now ...
#22
Posted 06 June 2004 - 12:25 PM
Crankymonky
#23
Posted 06 June 2004 - 12:56 PM
So, to sum it up, what language should I start with if 3d video games are my goal?
~Vintage
~Al Capone
#24
Posted 06 June 2004 - 05:01 PM
#include <windows.h> #include <GL\gl.h> #include <GL\glaux.h> int main(void) {
Perl is better for utilities, database stuff, string parsing, CGIs, and such. C++ is better where speed is critical which is pretty much anything using cutting edge graphics. Java is good for web-based games and anything where you need simple, lightweight graphics.
They all have similar syntax so the good news is that once you've learned one of them, the others will be much easier to pick up.
#25
Posted 05 July 2004 - 11:28 AM
Crankymonky-conspiracy theorist
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users