Jump to content


Photo

Yeeeeah Bitch!


26 replies to this topic

#1 cxwq

cxwq

    Member

  • Founders
  • 3,634 posts

Posted 14 May 2004 - 01:59 AM

Guess what? 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. To punish you all for your fucking insolence and for subjecting me to that forum holy war bullshit I'm going to post it here. Muahahahahahahahaha!

#! /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
  • 0
<meta name="cxwq" content="mostly water">

#2 Pineapple

Pineapple

    Old-school Admin

  • Contributors
  • 1,377 posts

Posted 14 May 2004 - 02:27 AM

Way to go, duder!

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-
  • 0
-Piney- of White Dog Hobbies Armory


<!--quoteo(post=209846:date=Feb 5 2009, 06:27 PM:name=boom)--><div class='quotetop'>QUOTE(boom @ Feb 5 2009, 06:27 PM) View Post</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 xedice

xedice

    Member

  • Members
  • 306 posts

Posted 14 May 2004 - 11:45 AM

The sad thing is, I found it to be of mild interest...

Strikes a close resemblence to C++.
  • 0
Shmokin' weed, Shmokin' wizz
Doin' coke, drinkin' beers, Drinkin' beers beers beers
Rollin' fatties, Smokin' blunts
Who smokes the blunts? We smoke the blunts
-Jay

#4 cxwq

cxwq

    Member

  • Founders
  • 3,634 posts

Posted 14 May 2004 - 01:28 PM

The sad thing is, I found it to be of mild interest...

Strikes a close resemblence to C++.

Perl's syntax is very similar 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.
  • 0
<meta name="cxwq" content="mostly water">

#5 sporkboyofjustice

sporkboyofjustice

    Member

  • Members
  • 280 posts

Posted 14 May 2004 - 01:32 PM

Good job cxwq. I have to do a little e-basic every now and then and when I look at the main programmers code it gives me a headache (he's really good). I also get a headache when I looked at your code so I know it must be good:)
  • 0

#6 Alexthebeast

Alexthebeast

    Member

  • Members
  • 728 posts

Posted 14 May 2004 - 02:18 PM

You have to love perl. Such a pretty script.
  • 0
<Fooz> In a perfect world... spammers would get caught, go to jail, and share a cell with many men who have enlarged their penisses, taken Viagra and are looking for a new relationship.

#7 xedice

xedice

    Member

  • Members
  • 306 posts

Posted 14 May 2004 - 04:56 PM

That list is pretty nifty! And yes, in C++, I hate typecasting, it always gives me problems. But is Perl mainstream? I mean, most business applications use either Visual Basic or Visual C++ (Actually C# or .net is even newer). What I am asking is, what is the intended use of Perl? Client/Server use?
  • 0
Shmokin' weed, Shmokin' wizz
Doin' coke, drinkin' beers, Drinkin' beers beers beers
Rollin' fatties, Smokin' blunts
Who smokes the blunts? We smoke the blunts
-Jay

#8 cxwq

cxwq

    Member

  • Founders
  • 3,634 posts

Posted 14 May 2004 - 05:47 PM

Is Perl mainstream? Yes. Is it marketable? Not really.

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.
  • 0
<meta name="cxwq" content="mostly water">

#9 boltsniper

boltsniper

    Member

  • Contributors
  • 591 posts

Posted 02 June 2004 - 04:15 PM

You gotta love those down to the wire submissions. Very nice code CX. I have used Perl very little but from what I have done with it is seems extremely powerful. I do 90% of my coding in MatLab with the other 10 in Fortran.

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


.
  • 0

#10 GeneralPrimevil

GeneralPrimevil

    Member

  • Members
  • 578 posts
  • Location:West Michigan, in a basement, chained to a wall, with nothing but a puter and a NiteFinder to keep me busy.

Posted 02 June 2004 - 05:19 PM

Ummm.(:o)Wow. For fun? Amazing, but not unbelievable. If you like what you do, might as well do it.

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.
  • 0
"Fear the man with one gun, for he probably knows how to use it."

#11 Grinch

Grinch

    Member

  • Members
  • 642 posts

Posted 02 June 2004 - 05:55 PM

** Ultra Snip **

You need a girlfriend. :o

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.

  • 0
Webmaster of Nerf World

Previously mrgrinch_nm!

#12 Crankymonky

Crankymonky

    It's The Dean!

  • Members
  • 687 posts
  • Location:DC

Posted 02 June 2004 - 07:44 PM

\/ (), \/ () |_| /\/() +@ | |< 1337, \/ () |_| |_| $ 3 |_ 3 + + 3 |0 $
|.......|...........................|<............|......................................| \

Edited by crankymonky, 02 June 2004 - 07:49 PM.

  • 0
Tyranny Response Team

#13 boltsniper

boltsniper

    Member

  • Contributors
  • 591 posts

Posted 02 June 2004 - 08:14 PM

You need a girlfriend. :o

I`m actually engaged and getting married on July 3rd....
  • 0

#14 Zero Talent

Zero Talent

    Member

  • Contributors
  • 606 posts

Posted 02 June 2004 - 08:33 PM

I`m actually engaged and getting married on July 3rd....

Proof that there is hope for all geeks... Or at least engineers. :o

Hope all goes to plan, Bolt. Making a pressurized garter launcher?
  • 0
"'Revere me as hot! All others are not! THIS, I COMMAND!'"
- Death

#15 boltsniper

boltsniper

    Member

  • Contributors
  • 591 posts

Posted 02 June 2004 - 08:39 PM

Making a pressurized garter launcher?

That's a damn good idea......!
  • 0

#16 Half Newb Half Nerfer

Half Newb Half Nerfer

    Member

  • Members
  • 737 posts

Posted 03 June 2004 - 01:47 PM

I have not the slightist idea what this topic means.
  • 0

#17 cxwq

cxwq

    Member

  • Founders
  • 3,634 posts

Posted 03 June 2004 - 03:02 PM

I`m actually engaged and getting married on July 3rd....

Congrats!

I have not the slightist idea what this topic means.


Congrats!
  • 0
<meta name="cxwq" content="mostly water">

#18 Ragornocks

Ragornocks

    Member

  • Members
  • 415 posts

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...
  • 0
hug the fuck out of 'em, philippe!

#19 taita cakes

taita cakes

    Member

  • Members
  • 943 posts

Posted 05 June 2004 - 07:51 AM

just a little off topic, when you guys are quoting each other, and using personalised usernames etc. [i like the 9/16 newb reference] is this done by inserting an "=" in the quote tags?


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.

  • 0
Oh Kentucky, you are so fuggin awesome...

#20 Vintage

Vintage

    Member

  • Members
  • 462 posts
  • Location:Minnesota

Posted 05 June 2004 - 09:21 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.

~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.

  • 0
You can get much further with a kind word and a gun than you can with a kind word alone
~Al Capone

#21 taita cakes

taita cakes

    Member

  • Members
  • 943 posts

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 ...
  • 0
Oh Kentucky, you are so fuggin awesome...

#22 Crankymonky

Crankymonky

    It's The Dean!

  • Members
  • 687 posts
  • Location:DC

Posted 06 June 2004 - 12:25 PM

Well Vintage, I know no PERL, and I hate C++ graphics. However, I can use them. I just finished my sexy looking game of tic-tac-toe of C++. That uses very sexy graphics. Would anyone like to play? I hear the java is much better at graphics than c++, however I do not know java.

Crankymonky
  • 0
Tyranny Response Team

#23 Vintage

Vintage

    Member

  • Members
  • 462 posts
  • Location:Minnesota

Posted 06 June 2004 - 12:56 PM

What language are most PC games written in? I always assumed C++, but I was probably wrong then. Since I am good and computer modeling and animation, I thought it would be fun to try a 3d video game with my models.

So, to sum it up, what language should I start with if 3d video games are my goal?

~Vintage
  • 0
You can get much further with a kind word and a gun than you can with a kind word alone
~Al Capone

#24 cxwq

cxwq

    Member

  • Founders
  • 3,634 posts

Posted 06 June 2004 - 05:01 PM

If you're only getting into coding for graphics, C++ and OpenGL are the ticket. OpenGL is available as a C++ library so your programs will start something like this:

#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.
  • 0
<meta name="cxwq" content="mostly water">

#25 Crankymonky

Crankymonky

    It's The Dean!

  • Members
  • 687 posts
  • Location:DC

Posted 05 July 2004 - 11:28 AM

I just realized, the time on C's post is messed. The first one. He said he turned it in 3 minutes before the 23:55 due date. He posted nearly one hour before that time, conspiracy of one!

Crankymonky-conspiracy theorist
  • 0
Tyranny Response Team


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users