Pep8 Computer Assembler: программа Блэкджек - PullRequest
0 голосов
/ 04 декабря 2018

Мне трудно собрать программу, которая по сути играет в игру в блэкджек (также известную как 21) в коде ассемблера Pep8.Я уже создал Генератор случайных чисел для программы, и я борюсь с основной частью остального кода.Ниже прокомментирован Генератор случайных чисел, где я собираюсь поставить игру в блэкджек:

     BR      main        
seed:    .BLOCK  2           ;global variable
numOfNum:.BLOCK  2           ;global variable
randNum: .BLOCK  2           ;global variable
index:   .BLOCK  2           ;global variable
cardVal: .BLOCK  2           ;global variable
ace:     .BLOCK  2           ;global variable
count:   .BLOCK  2           ;global variable
wager:   .BLOCK  2
payout:  .BLOCK  2
count2:  .BLOCK  2
hitHold: .BLOCK  2
wallet:  .BLOCK  2


main:    STRO    prompt1,d   ;prompt for seed
     CHARO   '\n',i      ;line break
     CHARO   '\n',i      ;line break
     DECI    seed,d      ;input seed
     DECI    wallet,d    ;wallet
     DECI    cardVal,d   ;card value
     DECI    count,d     ;turn count
     DECI    wager,d     ;wager
     DECI    payout,d    ;payout amount
     DECI    count2,d
     STRO    prompt2,d   ;prompt for number of outputs
     STRO    prompt3,d   ;prompt to hold or hit
     CHARO   '\n',i      ;line break
     DECI    numOfNum,d  ;input number of outputs user wants
     CHARO   '\n',i      
     STRO    outpMsg1,d  ;output 'Result for numOfNum  '
     DECO    numOfNum,d  
     STRO    outpMsg2,d  ;output ' with seed seed'
     DECO    seed,d      
     CHARO   '\n',i
     DECO    cardVal,d
     DECO    ace,d
     DECO    count,d
     DECO    wager,d
     DECO    payout,d
     DECO    count2,d


     LDA     index,d     ;(index = 0,
     STA     index,d

 for:     CPA     numOfNum,d  ; index < numOfNum
     BRGE    endFor      
     LDA     seed,d      ;load accumulator
     ASLA                ;multiply number in accumulator (seed) by 2 4 (2^4) times then...
     ASLA                
     ASLA                
     ASLA                
     ADDA    seed,d      ;makes it so that accumalator is multipled by 17
     ADDA    101,i       ;'c' value from eqution
     ANDA    0x001F,i    ;num mod 32
     STA     randNum,d   
     STRO    msg,d       ;output message
     DECO    randNum,d   ;output answer
     CHARO   '\n',i      ;line break
 ;new seed
     LDA     randNum,d   
     STA     seed,d      
     LDA     index,d     ;index++)
     ADDA    1,i         
     STA     index,d     
     BR      for

endFor:  STRO    endMsg,d    
     STOP 

msg:     .ASCII  "num = \x00"
endMsg:  .ASCII  "Done. \x00"
outpMsg1:.ASCII  "Result for \x00"
outpMsg2:.ASCII  " numbers with seed \x00"
prompt1: .ASCII  "Input a seed number. \x00"
prompt2: .ASCII  "How many numbers do you want? \x00"

;prompt to play
prompt4: .ASCII  "Would you like to play?"

;if yes
if:
;assign the first card to both count1 and count2 from 1-11
else:
prompt5: .ASCII  "Okay, get lost."
endIf:

;if wallet is less than 5 then you cannot play
if:
prompt6: .ASCII  "Sorry, you don't have enough money to play."
endIf:

;if wager > wallet, then you cannot play
if:
prompt7: .ASCII  "Sorry, you can't wager that amount. Either change your amount or get out."
endIf:

prompt3: .ASCII  "Would you like to hit or hold?"

;if hit
if:
;randomly increment both player's hands from 1-11

;ask to hit or hold
prompt11: .ASCII  "Would you like to hit or hold?"
if
;if hit increment then check requirements to win/lose
;if > 21
if:
prompt8: .ASCII  "Welp, you lost, good job."
;if < 21 ask to hit or hold
else:
endIf:
endIf:
endIf:

;if hold and less than opponent
if:
prompt8: .ASCII  "Welp, you lost, good job."
elseIf:
;if greater than 21
prompt9: .ASCII  "Welp, you lost, good job."
else:
;if hold and greater than opponent and less than 21
prompt10: .ASCII  "Well, look at that, you actually won. Here is your money."
;Increment wallet based on wager amount.
endIf:
     .END                  
...