-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm.txt
46 lines (37 loc) · 2.63 KB
/
algorithm.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
main:
0.1: print the instructions using a function
0.2: clear screen and set console background color to "f0"
0.3: call play function
0.4: ask user if they want to play other hand, if no then exit
->if yes then repeat from 0.3
play:
1.1: shuffle the cards using a function and push the shuffled cards to the stack of the cards
1.2: assign the top 2 cards of stack to user's cards(decrement top) and top 2 cards of stack to computer's cards(decrement top)
1.3: print one computer card and both of user's card
2.0-> 1st for loop: to convert face cards and ace card's value(for user)
2.1: if the card is ace, let user choose the value of ace as 11 or 1 and then add it to player cards sum
2.2: else if call convert_facecard function and if the rem is is 10 then add 10 to player cards sum
2.3: else add pcard[i]%100 to player cards sum
2.4: if(psum>21) then player loses
2.5: if(psum=21) then player wins
2.6-> print player card's sum
3.0-> 2nd for loop: whether player wants more cards
3.1: if user stands his hand(does not hit) then print his card's sum and exit the for loop.
3.2: [i=0]if user wants more cards then assign the card on top of stack(decrement top) to user and print that card.
3.3: repeat steps 2.1 to 2.5
3.4: goto step 3.1
3.5-> if player cards reach up to 5(i=3) and sum of player card's is less than 21 then player wins.
4.0-> print computer's two cards.
4.1: if both cards are aces then set comp cards sum to 12.
4.2: else if both cards add upto 21 its a blackjack and comp wins
4.3: else if any one card is ace then randomly select value of ace as 1 or 11.
4.4: else call convert_facecard functions for 1st[i] and 2nd card[1] and print comp card's sum
5.0-> 3rd for loop: giving cards to computer until sum of its cards is less than 17
5.1: for loop will only run through if comp cards sum is less than 17.
5.2: [i=0]assign top of stack card to comp card(i+2) and print that card.
5.3: if it is an ace then if the comp card sum is less than 21 then 11 is added to comp card sum else 1 is added.
5.4: else value returned from calling convert_facecard is added to comp card sum.
5.5-> if comp cards reach up to 5(i=3) and sum of comp card's is less than 21 then comp wins.
6.0-> if comp cards sum is greater than 21 or player sum is greater than comp card sum then player wins.
6.1: else if both sums are equal then it is a push.
6.2: else if player card sum is lesser than comp card sum than comp wins.