Assignment 1nbspdescription this first assignment will

Assignment Help Application Programming
Reference no: EM13347248

Assignment 1:

 Description: This first assignment will allow you to become more comfortable with threads and the basic issues associated with thread programming. In particular, you will be creating a simple multi-threaded application called Robin Hoods. As you may recall, Robin Hood was celebrated for "robbing the rich and giving to the poor." Your application will do something similar.

     In short, you will create a multi-threaded competition in which opposing Robin Hoods will attack one another and try to take each other's gold coins. Occasionally, they will donate some of their winnings to the community. To simulate the attack, each Robin Hood will be assigned a Band of Merry Men (or Women) with which he (or she) can do battle. When given the chance, Robin will challenge as many other competitors as possible. If he is victorious, he will then take some share of the gold coins of the loser. Robin will enter combat by: (1) randomly selecting one of his enemies as a target, (2) selecting a random percentage of his gold coins as a wager, and (3) selecting a random number of his merry folk to do battle. Victory always goes to the competitor who brings the most soldiers into battle.

    So how does this work? As you may have guessed, each of our Robin Hoods is represented by a thread. Each thread operates independently from the others. (i.e., it will be scheduled independently). That being said, the threads will have to share data in some fashion. While there are a number of ways that this process could be represented, you will do so by providing a "challenge" list for each competitor. As challenges are issued they will be placed into a list assigned to a specific Robin/thread. A challenge would consist of the (i) challengers ID (ii) the number of soldiers sent by the challenger (iii) the amount of the wager. When the target thread receives CPU control, it will be able to read from that list and respond to the challenge. It does so by first checking to see if it has enough money to match the wager. If not, this Robin/thread automatically loses and all his money goes to the challenger. If he does have enough money, he will select a random number of his own men and then compare this to the number provided by the challenger. The winner gets the appropriate number of gold coins from the loser (in a tie, nobody wins).

    Of course, Robin wouldn't be a hero if he didn't donate some of his winnings to the poor. Therefore, after every ten victories, Robin selects 10% of his current wealth and donates it to a community fund (the amount should be rounded to the nearest dollar so that we only work with integers). He may make many such contributions as the competition is running. It must be possible to keep track of everyone's contributions since the "winner" will ultimately be the most generous Robin.

    There are a few other details that need clarification. First, if the counts of coins and soldiers are purely random, then this would produce a sort of stalemate. In other words, every Robin would win about as much as he loses. Real life isn't like this so we will make some Robins a little better than others. To do this, we will vary the size of the Merry Men. Specifically, each Robin/thread gets one more soldier than the preceding Robin. So Thread 1 has one soldier, Thread 2 has two soldiers, ...Thread n has n soldiers. What this means is that, over time, a winner would actually emerge. That being said, the randomness in the challenge process allows some upsets. For example, Thread 100 could wager 100% of its coins but send just 2 soldiers to do battle with Thread 4, who sends 3 soldiers. Thread 100 would lose and be out of the game. In general, though, higher numbered threads should do a lot better.

    We also need a mechanism to provide basic parameters to the game. We will do this through some simple command line parameters. Assuming that the application is called RobinHoods, an invocation might look like this:

The parms thread_count, iteration_count, and coin_count are all integers. thread_count should be a number between 2 and 10. iteration_count can be a number between 1 and 100 million. And coin_count can be a number between 10 and 1 million.

    So, to recap, the idea is as follows. You will accept the arguments passed to the application at run time. A summary of these parms will be be printed immediately to the console, along with the total number of coins available (i.e., thread_count * coin_count). You will then generate thread_count threads, and each will compete when it gets the CPU. It will do so by generating iteration_count challenges, using a simple looping mechanism. However, before each individual challenge is generated, the thread must check its own challenge queue. If it is not empty, it must process all challenges that have been placed there by other Robins/threads. In other words, it must adjust the two coins counts as necessary (i.e., winner and loser). Only then does it continue with the loop. Each time ten victories have been recorded, Robin donates 10% of his current total to charity. If Robin runs out of money, however, a notice must be printed immediately to the console and the thread should no longer participate in the competition.

    Once the iterations are completed, and ALL challenge lists are empty, the main thread will summarize the results and print the results to the console. In short, it should order the Robins from most to least successful, in terms of the number of coins donated to charity. You should also list the coins still owned by each Robin (i.e., not donated). Finally, you should provide the total of all donated coins, plus the total of all coins still possessed by the remaining Robins. If your threads cooperated properly, this total should be the same as the number of coins available at the beginning of the process.

Reference no: EM13347248

Questions Cloud

Prepare a speech that involves communicating changes the : prepare a speech that involves communicating changes. the topic involves communication changes personal changes or
Parts 1 student is to imagine that they work for a : parts 1. student is to imagine that they work for a real-life company that has international operations. their board of
Please write project report and provide cross-synthesis an : please write project report and provide cross-synthesis. an interesting effect in electronic music synthesis is to
1 assume that you have tried three different forecasting : 1 assume that you have tried three different forecasting models. for the first the mad 2.5 for the second the mse
Assignment 1nbspdescription this first assignment will : assignment 1nbspdescription this first assignment will allow you to become more comfortable with threads and the basic
Essay questionsquestion 1 you are designing a grocery : essay questionsquestion 1 you are designing a grocery delivery business. via the internet your company will offer
Question 1 you are designing a grocery delivery business : question 1 you are designing a grocery delivery business. via the internet your company will provide staples and frozen
Normalizationpractice on topic of normalization for each of : normalizationpractice on topic of normalization for each of the following questions give the revised table
Question 1 which of the following events would be recorded : question 1 which of the following events would be recorded as an accounting event? a.a guest purchases a meal in a food

Reviews

Write a Review

Application Programming Questions & Answers

  Rtl sa is a company which develops bespoke solutions for

rtl sa is a company which develops bespoke solutions for the rubber industry. they produce both rubber compound which

  Problemthe manager of the super supermarket would like to

problemthe manager of the super supermarket would like to be able to compute the unit price for products sold there. to

  Write a paper on mcdonaldsethics and social responsibility

write a paper on mcdonalds.ethics and social responsibility at mcdonaldspaper includesabout mcdonaldscorporate social

  Question 1we are given the following knowledge base of

question 1we are given the following knowledge base of travel informationnbspbycaraucklandhamilton.

  Basic requirementsscreen one has three edittext views and

basic requirementsscreen one has three edittext views and one button.the edittext views allow you to enter a students

  Problem build a class for a type called fractionnbspthis

problem build a class for a type called fraction.nbspthis class is used to show a ration of two integers.nbsp include

  The increasing need to travel and lifestyle changes of

the increasing need to travel and lifestyle changes of society has made airlines industry one of the most demanded and

  Produce a project plan and an interim description of the

produce a project plan and an interim description of the project developmentproblem 1. northern lights alert service.

  1 object oriented programming class hierarchies

1. object oriented programming class hierarchies inheritance and virtual functions in this part of the assignment you

  Discussion htmlcssjavascript placementnbspplease respond to

discussion htmlcssjavascript placementnbspplease respond to the followingcompare and contrast the process of adding

  If the user wants to read the input from a file then the

if the user wants to read the input from a file then the output will also go into a different file. if the user wants

  Question 1part 1 conditional logicconditional logic is used

question 1part 1 conditional logicconditional logic is used within your application to make decisions during the

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd