1 / 18

T ask O riented P rogramming i n using Rinus Plasmeijer – Bas Lijnse - Peter Achten

T ask O riented P rogramming i n using Rinus Plasmeijer – Bas Lijnse - Peter Achten Pieter Koopman - Steffen Michels - Jurriën Stutterheim Jan Martin Jansen (NLDA) - Laszlo Domoszlai (ELTE) ASSIGNMENTS Radboud University Nijmegen. 1. Getting started.

qiana
Download Presentation

T ask O riented P rogramming i n using Rinus Plasmeijer – Bas Lijnse - Peter Achten

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. Task Oriented Programming in using Rinus Plasmeijer–Bas Lijnse- Peter Achten Pieter Koopman- Steffen Michels-JurriënStutterheim Jan Martin Jansen (NLDA) - Laszlo Domoszlai (ELTE) ASSIGNMENTS Radboud University Nijmegen

  2. 1. Getting started • Start the CleanIDE and open (‘File:Open… (Ctrl+O)’) the project at:iTasks-SDK/Examples/BasicAPIExamples.prj • Create and launch (‘Project:Update and Run (Ctrl+R)’) the server application • Open your favorite web browser and navigate to: http://localhost/  • Log in anonymously by pressing the ‘Continue’ button giving   

  3. 2. Tasks panel • Determine the relation between the tasks panel  and the definition of the function basicAPIExamples in the main module BasicAPIExamples.icl 

  4. 3. Persistent tasks • Start  ‘Interaction with basic types’ tasks from the tasks panel • The work view panel  displays the tasks assigned to you • The task view panel  displays the current state of these tasks • In the task view panel, manipulate tasks • At any stage, close  a task in the task view panel and reopen it      

  5. 4. Custom types • Study the relationship between the type of the task ‘Enter a person’ and the rendered interactive task • Do the same for the ‘Enter multiple persons’ task • Add a task named viewPerson to ‘Interaction with custom types’ that merely views a person using viewInformation with an empty list ([ ]) of ViewOption-s.

  6. 5. Customized view • In the task viewPerson, add a ViewOption element that limits the view to the current name and gender of the person. What is the effect of this change? • In the task enterPerson, add an EnterOption element that limits entering information to a name and gender only. The dateOfBirth field is always set to Nothing. What is the effect of this change? • Tips: • in the CleanIDE you can quickly find the definition of a function or type as follows: • double-click the identifier while holding Ctrl selects the definition • double-click the identifier while holding Ctrl+Altselects the implementation • in the CleanIDEthe command 'Help:Help:UserManual.pdf' opens the user manual of the CleanIDE. Appendix A and B summarize the standard key mappings and shortkeys

  7. Intermezzo • At: https://wiki.clean.cs.ru.nl/ITasks#Snapshot_for_CEFP_2013_Course, download Ligretto_framework.zip • Unzip it in the same directory as BasicAPIExamples. This adds the following modules: • ligretto.dcl and ligretto.icl: a fairly complete logic model for the Ligretto case study • ligrettoTOP.dcland ligrettoTOP.icl:an incomplete start-up module in which you can create your cool version of Ligretto • In module BasicAPIExamples.icladd the following line: • import ligrettoTOP • and in function basicAPIExamplesadd an entry to play Ligretto: • ,workflow "Ligretto" "Play Ligretto"play_ligretto • Tip: • any task can be easily tested by adding it to the function basicAPIExamplesin the same way as done above for the task play_ligretto

  8. 6. Play with HTML • In module ligrettoTOP.icl you find functions that render a single card (view_card), the row of a player (view_row), and the ligretto pile (view_ligretto). Study these functions. • Create in a similar way the function view_hand :: Hand -> HtmlTag that displays the back side of the card on top of the conceal pile and the front side of the card on top of the discard pile. • Tip: • if you find the definition of type HtmlTagthen you will see that it is a Clean data representation of standard html-tags. With these tags you can insert your own html if necessary.

  9. 7. Viewing a Player • Extend module ligrettoTOP.icl with a new task:view_player :: Player -> Task Playerthat uses viewInformation and a ViewOption and the rendering functions defined in exercise 6. to show the current row, ligretto, and hand of the player.

  10. 8. Viewing the middle piles • Extend module ligrettoTOP.icl with a new task:view_piles :: [Pile] -> Task [Pile]that uses viewInformation and a ViewOption and the rendering functions to show the currently played piles of cards in the middle of the table.

  11. 9. Add people • In the browser, start the task 'Manage users'. • In the opened task, choose the menu 'Import & export' command 'Import demo users'. • This adds the following users to your system: Alice, Bob, Carol, Dave, Eve, and Fred.Their usernames and passwords are: alice, bob, carol, dave, eve, and fred. • Tip: • after adding these users you can log out of the application and log in again as one of the newly registered users.

  12. 10. Invite friends • A game of Ligretto is played with 2, 3, or 4 people. • Add the following task function to ligrettoTOP.icl: • invite_friends :: Task [User] • invite_friends • = enterSharedMultipleChoice "Select friends to play with" [] users • >>= \friends ->  • Finish  in such a way that only selections with the correct number of players are accepted • Tip: • after adding these users you can log out of the application and log in again as one of the newly registered users.

  13. 11. Shared data source • It is natural to model the 'middle' cards by means of a shared data source because all players have access to the middle cards. • Add the following shared data source to ligrettoTOP.icl: • middle_state :: Shared Middle • middle_state = sharedStore  • Finish  with an appropriate initial value for the middle cards. • It is convenient to model each individual player also by means of a shared data source because this gives you easy access to updates. • Add the following shared data source to ligrettoTOP.icl: • player_state :: Color -> Shared Player • player_state color = sharedStore ("player " <+++ color)  • Finish  with an appropriate initial value for a player with the given color.

  14. 12. Viewing the middle piles, now as shared view • Alter the task of assignment 8. (viewing the middle piles) to a viewSharedInformation task that displays the middle_state shared data source. • Alter the task of assignment 7. (viewing a player) to a viewSharedInformation task that displays the player_state of a player of some color.

  15. 13. One player plays a game of Ligretto • It is about time to learn a player how to play a game of Ligretto. Create for this purpose a new task function, game. This task function encompasses the following steps: • obtain a random integer necessary to shuffle the initial cards of the player (get randomInttask) • create an initial player (initial_player function from ligretto.dcl) • store the initial player in the corresponding player_state (assignment 11.) • create a shared view on the middle piles and the player (assignment 12.) • step into a new task, play_cards. (assignment 14.)

  16. 14. Playing the cards • play_cards keeps an eye on the middle cards and the player state, and uses that information to decide possible future actions. • Add the following task function to ligrettoTOP.icl: • play_cardscolor • = watch (player_statecolor>+<middle_state) • >>* • Study the new functions in this suggested structure: • watch • >+< • >>* • Finish  with appropriate actions (OnAction): • the player can put a row card on a (new) pile in the middle • the player can put a discard hand card on a (new) pile in the middle • the player can take the next three cards of the concealed pile • the player can shuffle all hand cards to restart with the concealed pile • Finish  with an appropriate predicate (OnValue): • immediately when the ligretto pile is empty, return the color of the player

  17. 15. All players play a game of Ligretto • You now have all ingredients to finish the main task: play_ligretto. This task encompasses the following steps: • invite friends to a game of Ligretto (assignment 10.) • clearing the middle_state pile to a correct value (assignment 11.) • use anyTaskto let all players play a game of Ligretto (assignment 13.) at the same time. The first player with an empty ligretto pile terminates this anyTask. • congratulate the winner! • Tip: • the anyTaskcombinator evaluates all tasks in its list until the first task that uses the return task function • a player is assigned work by means of the @: combinator

  18. 16. Suggestions for improvements… • There are a quite some options to extend this little case study: • create better looking cards, e.g. by means of jpeg files • currently the final score is not computed, this can be added • a player who makes an illegal move can be given a small time penalty • try to make a task that plays Ligretto itself (probably with some random timer to make it fair…) • …

More Related