<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar/1675978235894282640?origin\x3dhttp://carlthehero.blogspot.com', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>
Carl
092690
Isang College Freshie
UP Diliman - BS ECE
Dating Taga-Makati Science
Problemado sa Plates
Adik sa TV

September 2007 October 2007 November 2007 December 2007 January 2008 February 2008 March 2008 April 2008 December 2008
Padre Salvi Main Padre Salvi Annex



Designer: Exposed & SW
Images: Heroes Pictures
Brushes: 8nero
Textures: CS.net

Sunday, February 3, 2008
Machine Problem 02 - Simplified?

/*Para sa mga nagsabing madali lang ang buhay eee11 kay Tai....
Naghahasik na siya ng lagim ngayon.. Alam ko na ang purpose ng MP01.. Panghatak ng Grade.. HAHA.*/
Sa mga may alam kung paano gumawa ng isang card sa C

EEE 11 - MDET, MDEF, MLMH (SY 2007-2008)
MACHINE PROBLEM 02: Simplified Blackjack Card Game
DEADLINE: March 18, 2008

OVERVIEW:

Create a program that will simulate a Simple Blackjack Dealer.
The player starts with 10 points, which may increase or decease after each round.
The game ends when the user decides to quit, or when he/she has no more points.

RULES OF THE GAME:

The objective of the game is to get a total value that is higher than the dealer's total value
The maximum value is 21 and any value above 21 is considered invalid

Game cards

Cards are based on the 52-card deck.
There are 13 faces, each face has 4 suites (Spades, Hearts, Clubs and Diamonds).
Only the face is used to determine the value of the card.

Face

Numerical Cards Corresponding numerical value (e.g. 2 of Diamonds)
Jack, Queen, King 10
Ace 1 or 11, whichever gives a better total
The player's hand refers to the cards that he/she is currently holding.
Its total value is the sum of the individual card values

Here are sample hands and their corresponding totals:

Total

Ace of heart, Jack of spades 21
Nine of hearts, Four of spades, Ace of diamonds 14
Two of clubs, Queen of spades, 7 of hearts 19

Game flow

Dealer Shuffles a 52-deck card

Distribution:

Player and dealer get 2 cards each from the deck
Only the first card of the dealer is known/visible to the player
Both cards of the player should be known/visible

Hit/Stay:

Player can ask for additional cards from the deck until he/she is satisfied with the total
Request for additional card means "Hit"
The player "Stays" when the total is already acceptable
The player automatically "Stays" on the following events:

Player gets a Blackjack (one Ace and a card whose value is equivalent to 10)
Player gets a value greater than 21 (bust)
Player already has 5 cards

Dealer's turn:

The dealer should get cards from the deck until a value of 17 is reached
This is regardless of the value of the player's hand

Compare hands:

Comparison is mainly based on the total value of the hands except for the following:
A blackjack is higher than any value, including 21
5-card hands that totals to a value less than or equal to 21 can only lose to a blackjack
A value greater than 21 is considered less than any valid hand

A draw is declared if:

both parties get Blackjack
both parties have 5-card hands less than or equal to 21 (regardless of the total)
both parties bust (regardless of the total)
both parties have the same total

Player check:

The game ends when the player has 0 points
The player can also choose to end the game after every round

Point system:

Player starts with 10 points:
After every round, the player's points is updated based on the following:
Draw 0 point
Only the player gets a blackjack +2 points
Player's hand is better +1 point
Dealer's hand is better -1 point

OTHER REQUIREMENTS:
- The deck should be re-shuffled at least once at the start of every round
- There should be only one instance of each card in every round
- The program should display all the cards of the player (not necessarily at the same time)
The face and suite of each card should be displayed or made known to the user
You can use/experiment with the special ASCII characters for the display
No specific format on the display
- The total value of the player's hand should be displayed on the following events:
After dealing
After getting a card (hit)
When the user "stays" with his hand
- Only one of the cards of the Dealer should be visible to the player after dealing the cards
- Show the rest of the cards of the Dealer and its total value at the end of every round
- You are free to use any of the C mechanisms discussed in class

SUBMISSION:

- Add the following header at the start of the source file
- Submit the source file, with the following naming convention _MP02.c
- Put comments to describe each major section of the code (e.g. loops, calculations,
operations that are not obvious)
- Upload your source code to the website
- Students may be requested to discuss/defend their submissions
* This is particularly true for students that use special algorithms / techniques
/*
* EEE 11 -

* ID# Name
*
*
*
*
*/

GRADING / CHECKING:
- 10% = Builds without warnings
- 10% = Error handling / recovery
- 20% = Documentation / Readability / Coding Style
- 60% = Able to perform expected basic operations
- 10% = User Interface (additional points)

APPENDIX: RANDOM NUMBER GENERATION

#include
#include /* for randomizer functions */
#include /* for time() function */
#define MAX_VALUE 100

int main(void)
{

int value;
srand(time(NULL)); /* initialize randomization, based on the current time */
/* different methods of using rand() to generate 0 to (MAX_VALUE-1) */
/* rand() generates a number between 0 and RAND_MAX */
value = MAX_VALUE*((float)rand() / (1+RAND_MAX));
printf("Random # 1: %d\n", value);
value = rand() % MAX_VALUE;
printf("Random # 2: %d\n", value);
/* add offsets to get ranges like 1 to MAX_VALUE */
value = MAX_VALUE*((float)rand() / (1+RAND_MAX)) + 1;
printf("Random # 3: %d\n", value);
value = rand() % MAX_VALUE + 1;
printf("Random # 4: %d\n", value);
return 0;
}


|

I save the cheerleader, You save the world @ 9:05 AM