Blackjack C Program Code


Lockheed Martin will integrate satellite buses and payloads with data processors.

Let's hope your teacher doesn't know how to play blackjack! You're initially dealt 2 cards, before you hit or stay, not one. If you go over 21, and the dealer goes over 21, you do not win. C# (CSharp) Blackjack Card - 30 examples found. These are the top rated real world C# (CSharp) examples of Blackjack.Card extracted from open source projects. You can rate examples to help us improve the quality of examples. Defense Advanced Research Projects Agency Program Detail. Similarly Tagged Content.

WASHINGTON — The Defense Advanced Research Projects Agency awarded Lockheed Martin a $5.8 million contract for satellite integration work for the Blackjack program, the company announced April 24.

Blackjack is a project to deploy a constellation of 20 satellites in low Earth orbit by 2022 and demonstrate that a LEO system can provide global high-speed communications.

Lockheed Martin will define and manage interfaces between Blackjack’s satellite buses, payloads and the so-called Pit Boss autonomous data processor. The work will be performed at the company’s satellite manufacturing plant in Sunnyvale, California.

“This is an exciting new approach to plug-and-play design for LEO,” said Sarah Reeves, vice president of missile defense programs at Lockheed Martin.

With Blackjack, DARPA seeks to demonstrate key technologies needed for a global high-speed network in LEO that the Defense Department can use for broadband communication and can adapt for other purposes like missile defense or navigation.

During the satellite integration phase of the program, multiple types of payloads provided by different vendors will be evaluated for use in communications, missile defense, PNT (positioning, navigation, timing) and ISR (intelligence, surveillance, reconnaissance).

For the Blackjack program, DARPA has selected buses from Airbus, Blue Canyon Technologies and Telesat. Payload suppliers include Collins Aerospace, Raytheon, Northrop Grumman, Trident, SA Photonics, Airbus, Systems & Technology Research, Sky Quantum and L3Harris. Scientific Systems Company, SEAKR Engineering and BAE Systems are developing Pit Boss concepts.

DARPA wants to make plug-and-play satellites where new payloads can be added without having to redesign the bus. That approach would allow the military to speed up the production and lower the cost of satellites compared to traditional acquisitions of custom-built spacecraft.

The plan is to launch the first two satellites in 2021 and 18 more in 2022.

Please enable JavaScript to view the comments powered by Disqus.

BlackJack Program Description

The code for the program begins with a clear (clc) statement to clear anything currently within the command window and workspace. Once this has run, three different arrays (assigned to variables deck, deck_value, and card_names) are then created. These arrays will serve as the basis for the rest of the following code. Once the arrays have been created, a print statement is used to create the welcome screen for the player, and an input is written to let the player choose when to proceed. After the game has been initialized the choice1 variable is set equal to 1 and a while loop that includes the rest of our code is set to run while that variable remains equivalent to 1 and stop if the variable’s value switches to 0. At the end of our code the choice1 variable is set equal to the player’s input, which will determine if the code should rerun again based on the player’s choice.

At the start of the code within the loop two variables are created, d and dealer_ace_card, to create the basis of a while loop that will run twice in order to deal two cards to the dealer. Within the loop, the program chooses a random number out of the length of the deck array using the randi and length operators. Once this number is chosen, it then goes to that position in the deck array and assigns the number to the variable card. The script then looks for the value associated with that card variable by going to the same position in the deck_value array and assigns that number to card_value2. The same process is used to get the correct position within the card_names string array. This value is assigned the variable card_name. In order to correctly hide the dealer’s first card, two if statements are included within the loop. If the code recognizes that it is the first time the loop has run (d = 1), it will store the first card in the variable first_card to be later displayed. However, if it is the second time the loop has run (d = 2) the code will print a message showing the dealer’s second card. Another if statement is then included to register if any of the cards dealt are an ace. If so, the value of dealer_ace_card is set equal to 1. This allows the code to register that there is an ace in the dealer’s hand. At the end of each iteration of the loop the deck array is updated to take out the card drawn. After the loop has been completed, the sum of the card values found is added together and assigned to the variable dealer_sum. In rare cases, the dealer may have drawn two aces at this point, which would make the dealer_sum 22. In order to account for this, an if statement was made to check if the dealer_sum is above 21 at this point. If so, one of the ace values is changed to 1 by subtracting 10 from the current dealer_sum.

Almost the exact same process described above is then repeated for the player. Two variables, i and ace_card, are created and a while loop is made to run twice. The variable card is chosen, then card_value and card_name are found in reference to that variable. An if statement is created to recognize if an ace has been drawn. For each iteration of the loop, the card drawn is displayed, and the value associated with that card is taken out of the deck array. After the loop has completed, a similar if statement is made to check if the player_sum has exceeded 21 at this point. If so, the value of one of the aces is changed to 1 by subtracting 10 from the player_sum. Then a print statement displays to the player the current total they have. At this point, the initial steps of the game have been completed.

Before proceeding to the player’s choices, the code first checks if either the player or the dealer have achieved BlackJack (21 in your starting hand). Three if statements are created to check these conditions. The first checks if the player_sum is equivalent to 21 while dealer_sum is not. If these conditions are met, a message is printed saying that the player has achieved BlackJack. The second does the reverse, checking if dealer_sum is equivalent to 21 while player_sum is not. If these conditions are met, a message is printed saying that the dealer has achieved BlackJack. The last runs if neither player_sum nor dealer_sum are equivalent to 21. If so, instructions are printed using an fprintf statement telling the player to choose 1 for hit and 0 for stand, and the next loop begins.

The next loop is a while loop that is created to run while player_sum is less than 21 and dealer_sum is not equal to 21. At the start of the loop, variable choice is set equal to the input of the question “Would you like to hit or stand?:” From the printed instructions above, the player knows to input 1 for hit and 0 for stand. An if statement has been created in order to ensure that the input is equivalent to 1 or 0. If the input isn’t equivalent then a print statement will run showing there is an invalid input and the player will be prompted with the input again. If the input of the variable choice is equivalent to 1, then another card will be drawn from the deck using the same process outlined above. A random number is taken out of the deck array and assigned to card. Then the card variable is used in order to get the corresponding values from deck_value and card_names, and the card variable chosen will be taken out of the deck array. Lastly, an if statement will be used to check if the variable ace_card is equivalent to 1 and the player_sum is greater than 21. If both conditions are met, the program displays a message showing that the player will bust if the ace stays the value it is currently, player_sum will have 10 subtracted from its total to account for the ace’s change of 11 to 1, and the ace_card variable will be set equal to 0 once again in order to show it has accounted for the ace. At this point the player will be prompted again with the same input asking to hit or stand. If the player chooses 1 then another card is drawn in the same fashion as above. If the player chooses 0, the code knows to display the player’s final total stored in player_sum and to break out of the code. The loop will also end if player_sum exceeds 21 as values are added.

Once the loop has ended, an if statement is set to to check if player_sum has exceeded 21, and if so to display that the player has busted. An elseif is included to run if the starting_player_sum doesn’t equal 21, the player_sum is less than or equal to 21, and the dealer_sum doesn’t equal 21. If these logicals are found to all be true the dealer’s first card and starting total is printed and the next loop begins. The next loop is a while loop set to run while dealer_sum is less than player_sum or dealer_sum is less than 17. The loop displays that the dealer has hit and then includes an input in order to slow down the outputs shown in the command window. The exact same process for the previous loop is used except the values are stored in card_value2 and added to the dealer_sum. If statements are also included to check for an ace and change the value if needed. An if statement within the loop checks if dealer_sum is greater than 21. If so the program will print that the dealer has busted and break out of the code. At the end of each iteration of the loop another input is included in order to let the player choose when to proceed. After the loop, an if statement is included to display the dealer has stood if he has gotten a value higher than player_sum or tied with player_sum at a value of 17 or above. Then multiple if and elseif statements are included to compare the values of player_sum and dealer_sum. If dealer_sum is greater than player_sum without going over 21, the dealer wins, if player_sum is greater than dealer_sum without going over 21, the player wins, if both variables are equivalent it’s a tie, and if both variables go above 21 the dealer wins. All of these are associated with the proper print statement. At this point the player is asked if they would like to play again. If so, the code restarts again at the start of paragraph 2.


  1. deck – An array of numbers 1 through 52. This will serve as all the cards within our deck
  2. deck_value – An array in equal size to the deck array. Includes all the possible values that a card could be and puts the value in the same position as that of the deck array.
  3. card_names – A string array of the same size as deck and deck_value. Includes the name of all cards within the deck put within a correlated position to display the correct card name with the associated value.
  4. choice1 – A variable initially set equal to 1 that determines whether the rest of the code within the while loop will run based on the players input after the first run.
  5. d – Allows the dealer to draw their inital hand while d is not greater than 2.
  6. dealer_ace_card – Determines if the dealer has an ace within their hand. Whenever the dealer draws an ace, the value of this variable changes
  7. card – Chooses a random number out of the length of deck and then goes to that position within the deck array.
  8. card_value2 – Reads what number the card variable landed on and goes to that position within the deck_value array.
  9. card_name – Reads the value of card and goes that position within the card_names string array.
  10. first_card – Stores what the first card drawn by the dealer was, but doesn’t display it.
  11. shown_sumStores the known second card value.
  12. dealer_sum – The total that the dealer has from the cards that have been drawn.
  13. i – Allows the player to draw their initial hand while i is not greater than 2.
  14. ace_card – Determines if the player has an ace within their hand. Whenever the players draws an ace, the value of this variable changes.
  15. card_value – Similar to card_value2, it records the number that the card variable landed on and goes to that position within the deck_value array, but for the player
  16. player_sum – The total that the player has from the cards that have been drawn.
  17. starting_player_sum – Keeps the total of the players first two cards to let the code recognize if the player got BlackJack.
  18. choice – Set equal to the input the player chooses. Lets the code know what to run based off if the player chooses hit or stand.

Over/Under 7 Program Description

Aol Blackjack Codes

The game starts off with saying clear and clc which removes all previous stored values for variables and empty’s the command window. The variable play is put in place for a while loop that contains the whole game to keep the game running without having to restart. The coins variable is also not included in the while loop so that it does not reset while the player loops back to the top of the game multiple times, it will remain constant through every run until they end the game. The while play1 encompasses the actual gameplay to create the loop of continuous play if desired. The next step is to create the visual displays by using the my_scene and dice_sprites variables. The code uses fprintf statements to tell the player their initial coin value and the options for choosing their bet of over or under. Then an input command is given to give the choice variable a value. A while loop is set up after that reads the input choice and checks if the input was not one of the given options, if not it says invalid bet and prompts the input statement for a correct input. When the correct input for choice is set, the same steps occur with the bet amount. An input statement calls for the player to insert the amount of coins they wish to bet and a while loop checks that bet to make sure it is not more coins than they currently have. When a valid bet is set the next step is to randomize two dice values by using the randi(6,1,2) function. This randomly generates a number 1 through 6 twice. Then using the sum(dice_roll) command, the two dice values are summed up and printed out using the fprintf command. The draw_scene variable is then used to match both of the dice rolls to the proper visual dice display. The next step is for a series of if elseif statements to compare the choice of the bet against the sum of the dice rolled. It first checks if the variable choice was given a value of 2 and the bet was greater than 7. If it was, an fprintf command says the player won and it changes the value of coins to initial coins plus the bet of coins. The elseif statement checks if the value of choice was not equal to 2 and the sum being greater than 7. This results in a loss signaling the fprintf command to say the player loses and changes the value of coins to be the initial coins minus the lost bet. This process is repeated with two more identical if elseif statements that checks based off of the other choice options. After the choice is checked and the correct win loss function is executed the next step of the code is to check the current total of the coins. Using an if statement, the value of coins is checked to see if it equals 0, if so the game is over because the player lost all their coins. The game will then exit the game loop and the player will have to rerun the code to start back over with a fresh set of coins. The player then is prompted with an input statement that asks if they would like to play again. Once again, a while loop is used to ensure the player has to input a valid answer to playing again and setting the play variable with a correct value. A final if statement checks if the value of play is 1 then it goes back to the top just like the first while loop indicates and plays the game again. If the value of play is 0 the game thanks the player for playing using an fprintf statement, then exits the game loop thus ending the code.


Blackjack C Program Codes

  1. play=1 This variable is created so it can be used at the end of the code, an if statement checks to see the new value of play from the input, defending on the input the game will stay in the loop or not
  2. coins=1000 This is the starting amount for betting and is edited later throughout the game
  3. bet= input this will be the amount of coins placed into the pot for the dice roll
  4. my_scene = simpleGameEngine(‘retro_simple_dice.png’,16,16,8) This creates the image display for the dice
  5. dice_sprites = 1:6 This sets up the variables for different sprites
  6. choice = input This is where the player puts in their bet which is then checked in an if else statement against the sum of the dice
  7. dice_roll = randi(6,1,2); this creates a random roll of a dice
  8. dice_sum = sum(dice_roll) this then sums of up the value of the two dice