SlideShare a Scribd company logo
1 of 34
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

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 

Recently uploaded (20)

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
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
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
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
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 

Winning MegaMinerAI