1 / 19

Practical session 8

Practical session 8. Assignment 3. Core Wars. Core Wars is a programming game in which two or more battle programs ("warriors") compete for control Programs move themselves around, modify themselves, attempt to destroy others by writing on them etc.

luyu
Download Presentation

Practical session 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Practical session 8 Assignment 3

  2. Core Wars • Core Wars is a programming game in which two or more battle programs ("warriors") compete for control • Programs move themselves around, modify themselves, attempt to destroy others by writing on them etc. • The object of the game is to cause all processes of the opposing program(s) to terminate

  3. Core Wars •  In the real core-wars: • A supervisory program runs one instruction of each program in turn. • No program knows where the others reside, and other complications

  4. Our game version • You use the co-routine mechanism to implement a simplified version of the core wars game: • Each warrior program is implemented as a co-routine. The warrior belongs to a “team” • Warrior performs some action. When done, control is transferred to a scheduler. • scheduler is our supervisor program (implemented as a co-routine, also). It selects the next co-routine to get its time-slice action. Selection is done in a round robin fashion.

  5. Co-routine table • Each co-routine warrior is settled in a co-routine table slot. The first table slot is dedicated to the scheduler co-routine. * * * * * SP CODE FLAGS Co-Routine Stack

  6. Warrior actions • Warrior performs one of the following actions (implemented as functions): • DUPLICATE: creates a clone of the current co-routine that belongs to the same “team”, in the first empty slot. Otherwise fails. • NUKE(i): kills a co-routine in slot i. That will cause the scheduler not to run the dead co-routine. • STUN: stuns (or freezes) up to m co-routines to be chosen by the currently running co-routine. Stunned co-routines do not get their turn to execute for x rounds

  7. Warrior type • You will be implementing three types of fighting co-routines, differentiated by their fighting strategies: • DUPLICATOR: applies the DUPLICATE action, unless no slots remain, in which case instead of DUPLICATE, it performs NUKE to the first slot containing a living enemy* co-routine (giving preference to non-stunned warriors). • Killer: whenever its turn occurs, NUKEs the next enemy co-routine. If no such co-routine exists, no action is taken. • Stunner: Whenever its turn occurs, stuns the next m living enemy co-routines that are not currently stunned. If there is no enemy to STUN, apply DUPLICATE. If DUPLICATE is also not possible, use NUKE on the next enemy. *enemy – co-routine from other team

  8. Warrior state • The 'flags' space in a co-routine structure can hold the status of a co-routine, and its team number. • The status is in the low order byte. • The stun counter is in the high-order word of the flags. • The team number is in the next to lowest order byte of the flags. • Possible status number for a warrior: • 0 - Dead/Empty space • 1 - Alive and well • 3- Stunned (any k>1) FLAGS (memory) STATUS STUN COUNTER TEAM #

  9. Scheduler • The scheduler decides according to the rules above which co-routine gets to run, and then resumes it.  • It is a simple 'round-robin' mechanism. • Performs 100 iterations over the entire table, and at the end of each, it prints the population status. • Prints the winning team - one with most living team members in the table.

  10. Technical Issues • From the command line, the user types: • The program name ‘corewars’. • A string argument, composed from ‘d’, ‘s, and ’k’ letters. • The string argument determines the number of participating co-routines, the warriors types (‘d’ for duplicator, ‘s’ for stunner and ‘k’ for killer) and their order. Each warrior is given a team number (starting from 1) • The created co-routine table will be of size 3*(input length)+1. • By default, a stunner selects two co-routines for the operation. A stunned warrior needs two turns to wait.

  11. Example >corewars dkksds d1 s6 s4 d5 d1 k2 k3 * * * * … 0)d1k2k3s4d5s6* * * * * * * * * * * *

  12. Example >corewars dkksds 2 2 d1 s6 s4 d5 d1 k2 * * * … 0)d1k2k3s4d5s6* * * * * * * * * * * *

  13. Example >corewars dkksds 2 2 d1 s6 d1 s4 d5 d1 k2 * * * … 0)d1k2k3s4d5s6* * * * * * * * * * * * 1 1

  14. Example >corewars dkksds d1 d1 s6 d1 s4 d5 d1 k2 * * * * … 0)d1k2k3s4d5s6* * * * * * * * * * * * 1)d1k2d1s4D5S6d1* * * * * * * * * * * 1 1

  15. Example >corewars dkksds 1 1 d1 d1 s6 s4 d5 d1 k2 * * * … 0)d1k2k3s4d5s6* * * * * * * * * * * * 1)d1k2d1s4D5S6d1* * * * * * * * * * * 1 2 1 2

  16. Example >corewars dkksds d1 d1 s6 d1 s4 d5 d1 k2 * * … 0)d1k2k3s4d5s6* * * * * * * * * * * * 1)d1k2d1s4D5S6d1* * * * * * * * * * * 2)d1k2* s4d5s6D1D1* * * * * * * * * * 1 1

  17. Example >corewars dkksds d1 d1 s6 d1 s4 d5 d1 k2 * * … 0)d1k2k3s4d5s6* * * * * * * * * * * * 1)d1k2d1s4D5S6d1* * * * * * * * * * * 2)d1k2* s4d5s6D1D1* * * * * * * * * * 1 2 1 1 2 1

  18. Example >corewars dkksds d1 d1 s6 s4 d5 d1 k2 * * … 0)d1k2k3s4d5s6* * * * * * * * * * * * 1)d1k2d1s4D5S6d1* * * * * * * * * * * 2)d1k2* s4d5s6D1D1* * * * * * * * * * 3)d1k2* s4D5S6d1d1* * * * * * * * * * 1 1

  19. Example >corewars dkksds 0)d1k2k3s4d5s6* * * * * * * * * * * * 1)d1k2d1s4D5S6d1* * * * * * * * * * * 2)d1k2* s4d5s6D1D1* * * * * * * * * * 3)d1k2* s4D5S6d1d1* * * * * * * * * * …. 100)d1k2* s4d5s6D1D1* * * * * * * * * * Winning team: 1

More Related