Question: write a function called calculate _ comprpg _ stats ( history , filename ) that takes the history and a string filename and calculates some

write a function called calculate_comprpg_stats(history, filename) that takes the history and a string filename and calculates some statistics on the actions played in the game.
Your function should calculate the number of attacks, defends, items, swaps, attempted damage, attempted protection, electricity used, and turns taken for each player based on game history and save this in csv format to the specified file name.
You may assume that the actions are formatted correctly and are the correct length for their action type.
Example 1:
>>> history =[[('Haskell Heroine', 'defend', 'Recursion Rebuff', 2,0),('Python Pal', 'item', 'Screen Repair Kit')],[('Linux Legend', 'attack', 'Root Reckoning', 4,2,5,['Haskell Heroine', 'Python Pal']),('Binary Bot', 'item', 'Debugging Tool')],[('Haskell Heroine', 'attack', 'Lambda Lunge', 3,1,0,['Linux Legend']),('Python Pal', 'item', 'RAM Boost')],[('Linux Legend', 'attack', 'Kernel Kick', 4,1,3,['Python Pal']),('Binary Bot', 'swap', 'Network Ninja')]]
>>> calculate_comprpg_stats(history, "example_game1_stats.csv")
Should produce the file:
player,attacks,defends,items,swaps,attempted damage,attempted protection,electricity used,turns taken
0,1,1,2,0,3,2,0,2
1,2,0,1,1,8,0,8,2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!