SlideShare a Scribd company logo
Winning MegaMinerAI
Writing Fast Code Fast
Bob Buehler
Overview
This is a messy presentation
Sorry
Ask questions?
Strategy
Our APIPathing
Base API
Solving
AI.cs
Solver.cs
Digger.cs
Pather.cs
Bb.cs
Pump.cs
Point.cs
x
y
x
y
x
y
x
y
x
y
Path finding interface
Keep it simple, right?
Start End
Path
Game
TilesUnits
Two sides to an interface
Breadth first search
open_queue = new queue(start)
closed_set = new set()
previous_map = new map()
while open_queue is not empty
current = open_queue.dequeue()
closed_set.add(current)
if current == end
return construct_path(end, previous_map)
else
for each n in neighbors_of(current)
if n not in closed_set
open_queue.enqueue(n)
previous_map.add(n, current)
Path finding algorithm
x
y
x
y
x
y
x
y
x
y
Start End
Path
NeighborGenerator
width height
Is_passable
BFS  Dijkstra’s  A*
Dijkstra’s is like breadth-first search except
• It can handle costs applied to steps
• get_cost(current, n)
A* is like Dijkstra’s except
• It can make better guesses about which way to
look first
• It does so by using a remaining-cost-heuristic
• calculate_h(n)
x
y
x
y
c
x
y
c
x
y
x
y
x
y
x
y
x
y
x
y
Flexible A*
x
y
x
y
x
y
Starts Ends
Path
maxYmaxX
x
y
x
y
x
y
Passables
costs
NeighborGenerator
heuristics
x
y
c
x
y
C# A*
What’s a Point?
x
y
What’s an IEnumerable?
System.Collections.Generic
• IEnumerable<T>
• GetEnumerator()
• IEnumerator<T>
• MoveNext()
• Current
• foreach (T x in e) { }
• Array<T>
• List<T>
• LinkedList<T>
What’s a BitArray?
new BitArray(width * height)
int index = y * width + x;
What the Func?
Func<T1, T2, TResult> myFunc;
Func<int, int, int> addEm = (x, y) => { return x + y; };
Func<int, int> squareIt = x => { return x * x; };
Func<int, int> squareIt = x => x * x;
C# A*
Uses of A*
To calculate a walking path
Uses of A*
To calculate where to spawn
Uses of A*
To calculate if a pump is pumping
Uses of A*
To calculate what trenches to dig
Uses of A*
To calculate what trenches to dig
Uses of A*
To calculate what trenches to dig
C# A* MegaMinerAI 11
Why rewrite?
• When do you rewrite code?
• When it’s not correct
• When it’s not fast enough
• When it’s not giving the information you need
• When it’s not accepting the information you have
• When it’s not easy to use
• When it’s not easy to understand
• When it’s broken because of another rewrite
Strategy
Our APIPathing
Base API
Solving
AI.cs
Solver.cs
Digger.cs
Pather.cs
Organize by dependency
Bb.cs
Pump.cs
Point.cs
What can C# do for you?
Good abstractions and base library
• IEnumerable<>
• Func<>
• BitArray
What can C# do for you?
Good abbreviations
• Lambda functions
• Type inference
What can C# do for you?
Extension methods
What can C# do for you?
Extension methods
What can C# do for you?
Extension methods
Conclusions
Write a flexible A*
• Multiple start points
• Multiple end points
• Configurable passability
• Configurable costs
Conclusions
Write code that doesn’t need rewriting
• Write tiny functions
• More correct
• More performant
• Write an input interface that doesn’t ask for extras
• More usable
• More understandable
• Provide output that is exactly what you’re willing to
support
Conclusions
Consider C#
• A very handy IDE
• More than fast enough
• The base libraries are solid
https://github.com/BobBuehler/megaminerai12

More Related Content

Similar to Winning MegaMinerAI

Behm Shah Pagerank
Behm Shah PagerankBehm Shah Pagerank
Behm Shah Pagerank
gothicane
 
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Computer Science Club
 
Map reduce programming model to solve graph problems
Map reduce programming model to solve graph problemsMap reduce programming model to solve graph problems
Map reduce programming model to solve graph problems
Nishant Gandhi
 

Similar to Winning MegaMinerAI (20)

Move from C to Go
Move from C to GoMove from C to Go
Move from C to Go
 
MapReduce Algorithm Design
MapReduce Algorithm DesignMapReduce Algorithm Design
MapReduce Algorithm Design
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
 
Lecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdfLecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdf
 
Ai1.pdf
Ai1.pdfAi1.pdf
Ai1.pdf
 
Behm Shah Pagerank
Behm Shah PagerankBehm Shah Pagerank
Behm Shah Pagerank
 
Pregel
PregelPregel
Pregel
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
 
Class[1][23ed may] [algorithms]
Class[1][23ed may] [algorithms]Class[1][23ed may] [algorithms]
Class[1][23ed may] [algorithms]
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
 
Distributed Graph Algorithms
Distributed Graph AlgorithmsDistributed Graph Algorithms
Distributed Graph Algorithms
 
Optimization for iterative queries on Mapreduce
Optimization for iterative queries on MapreduceOptimization for iterative queries on Mapreduce
Optimization for iterative queries on Mapreduce
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
Andrew Goldberg. Highway Dimension and Provably Efficient Shortest Path Algor...
 
State fair project ( Remote Car Parking System)
State fair project ( Remote Car Parking System)State fair project ( Remote Car Parking System)
State fair project ( Remote Car Parking System)
 
State fair project
State fair projectState fair project
State fair project
 
Map reduce programming model to solve graph problems
Map reduce programming model to solve graph problemsMap reduce programming model to solve graph problems
Map reduce programming model to solve graph problems
 

Recently uploaded

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 

Winning MegaMinerAI