Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Monte Carlo Methods
a case study
Dmitri Nesteruk
dmitrinesteruk@gmail.com
Hi!
• My name is Dmitri
• Quant finance
• Developer Evangelist @ JetBrains (2010-…)
• Visiting Researcher @
University of ...
Calculation of 𝜋𝜋
• Generate lots of points in
square
• Area of circle
𝜋𝜋𝑟𝑟2
• Area of square
4𝑟𝑟2
• ∴ 𝜋𝜋 = 4
𝑆𝑆𝑐𝑐𝑐𝑐𝑐𝑐 𝑐𝑐𝑐...
� 𝑒𝑒 𝑥𝑥2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
2
4
6
8
10
12
14
16
18
Poker (is largely bots  )
AH 7S
? ?
AS KH TC
try every single combination
6
C
6
D
win
win
loss
loss
loss
AH 7S
40% to win
Challenging (&geeky) games for heavy MC
HearthStone
• ~400 differentcards
• Player pick a deck of 30
• Each card has stationary and transient behaviors
• May affe...
Rules
• Stored in an XML file
• Parsed via boost::regex
• Result in creation of std::function objects
Everything affects everything
• This card gives bonus to other card
• When card enters play, …
• When card leaves play, …
...
Properties
• Properties are built-in in C#, not available in C++ or Java
• __declspec(property) compiler extension
• Suppo...
Change notifications
• We want to be informed when properties change
• Use boost::signals
• Let’s borrow .NET ideology!
Event Bus
• Global communication pipeline
• Entity signs up when enters game, disconnects on exit
• Also uses signal/slot ...
Realtime Analysis
• The game uses Unity
• Decompiled .NET libs
• Reverse-engineerProtocol Buffer definitions
• …
• PROFIT!...
Packet Capture
• Winpcap
• Capture game state
• Reanalyze at each significant change
Architecture
• Intel C++
• >10k Xeon cores
• 24x Intel Xeon Phi
That’s it!
• Monte-Carlo Methods in
Financial Engineering, Paul
Glasserman, Springer
• Boost
http://boost.org
• Course on ...
Monte Carlo C++
Upcoming SlideShare
Loading in …5
×

Monte Carlo C++

652 views

Published on

Slides from my MC talk at the C++ User Group, St.Petersburg, Russia, June 2014

  • Be the first to comment

Monte Carlo C++

  1. 1. Monte Carlo Methods a case study Dmitri Nesteruk dmitrinesteruk@gmail.com
  2. 2. Hi! • My name is Dmitri • Quant finance • Developer Evangelist @ JetBrains (2010-…) • Visiting Researcher @ University of Southampton (2002-…) • MVP Visual C# (2009-…)
  3. 3. Calculation of 𝜋𝜋 • Generate lots of points in square • Area of circle 𝜋𝜋𝑟𝑟2 • Area of square 4𝑟𝑟2 • ∴ 𝜋𝜋 = 4 𝑆𝑆𝑐𝑐𝑐𝑐𝑐𝑐 𝑐𝑐𝑐𝑐𝑐𝑐 𝑆𝑆𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 • Area ~ number of points r
  4. 4. � 𝑒𝑒 𝑥𝑥2
  5. 5. 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 2 4 6 8 10 12 14 16 18
  6. 6. Poker (is largely bots  )
  7. 7. AH 7S ? ? AS KH TC try every single combination 6 C 6 D win win loss loss loss AH 7S 40% to win
  8. 8. Challenging (&geeky) games for heavy MC
  9. 9. HearthStone • ~400 differentcards • Player pick a deck of 30 • Each card has stationary and transient behaviors • May affect 0, 1 or several other cards
  10. 10. Rules • Stored in an XML file • Parsed via boost::regex • Result in creation of std::function objects
  11. 11. Everything affects everything • This card gives bonus to other card • When card enters play, … • When card leaves play, … • This interaction method does not map well to OOP
  12. 12. Properties • Properties are built-in in C#, not available in C++ or Java • __declspec(property) compiler extension • Supported on at least Intel and MSVC compilers • A person structure keeps the person’s age • Age (read/write) • Only people older than 16 can vote • CanVote (readonly) • This is a derivative property (at runtime you need an std::function)
  13. 13. Change notifications • We want to be informed when properties change • Use boost::signals • Let’s borrow .NET ideology!
  14. 14. Event Bus • Global communication pipeline • Entity signs up when enters game, disconnects on exit • Also uses signal/slot paradigm
  15. 15. Realtime Analysis • The game uses Unity • Decompiled .NET libs • Reverse-engineerProtocol Buffer definitions • … • PROFIT!!!
  16. 16. Packet Capture • Winpcap • Capture game state • Reanalyze at each significant change
  17. 17. Architecture • Intel C++ • >10k Xeon cores • 24x Intel Xeon Phi
  18. 18. That’s it! • Monte-Carlo Methods in Financial Engineering, Paul Glasserman, Springer • Boost http://boost.org • Course on Boost at http://pluralsight.com • Send feedback to: @dnesteruk dmitrinesteruk@gmail.com

×