Tutorial Moodle VPL Rock-Paper-Scissors -- Python

From DftWiki

Jump to: navigation, search

--D. Thiebaut (talk) 08:50, 11 June 2014 (EDT)



Contents

MoodleVPLLogo.png



Moodle VPL Tutorials



This tutorial builds on the first one in the series, which should be done first, as the present tutorial skips some steps. In this tutorial we setup a VPL activity that will allow students to submit Python programs that play the game of Rock-Paper-Scissors.

Setup


  • Moodle Version 2.7 + (Build: 20140529)
  • VPL Version 3.0.1
  • For details on how Moodle and VPL were installed, go to this page.


VPL Activity


Here are the main settings for the new VPL activity:

MoodleVPLPythonRockPaperScissors1.png

MoodleVPLPythonRockPaperScissors2.png



Tips & Tricks


To generate the vpl_evaluate.cases file, I found that running the program first and capturing its output, and then using this text to generate the input and output sections of the vpl_evaluate.cases file is quick and simple.

Testing


  • In the Administration box, click on Test activity, then Edit, and enter the solution program below:


computer = 0
user = 0
while abs( computer - user ) < 3:
  play = input( "> " ).upper().strip()
  if len( play ) != 2:
      continue
  cPick = play[0]
  uPick = play[1]
       
  if uPick == cPick:
     print( "Tie" )
     continue
     
  pair = cPick + uPick
  if pair in [ "PR", "SP", "RS" ]:
     computer += 1
     print( "Player 1 wins" )
     continue
  else:        
     user += 1
     print( "Player 2 wins" )
     
if computer > user:
     print( "winner: Player 1 (%d to %d)" % ( computer, user ) )
else:
     print( "winner: Player 2 (%d to %d)" % ( user, computer ) )


  • Save, and Evaluate
  • Verify that the program runs and passes the two tests.


MoodleVPLPythonRockPaperScissors3.png


This concludes this tutorial