Solving Games in Java (Part I) - Practical Java Projects

Java programming: using search techniques (DFS, BFS, A*, IDA*, minimax, alpha-beta pruning) in practice.
4.5 (13 ratings)
Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
1,419 students enrolled
50% off
Take This Course
  • Lectures 24
  • Length 1 hour
  • Skill Level Intermediate Level
  • Languages English, captions
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works


Find online courses made by experts from around the world.


Take your courses with you and learn anywhere, anytime.


Learn and practice real-world skills and achieve your goals.

About This Course

Published 10/2014 English Closed captions available

Course Description

You know Java basics, maybe even took a data structures course and wonder how your knowledge could be used in practice? Looking for a coding project to hone your skills? Want to outplay or baffle your friends with a program that plays better than them? Join these series to build game solvers, game AI and Flash game bot! From scratch!

Solving Games in Java course series are targeted for demonstration of practical usage of searching techniques like depth-first search, breadth-first search, A* search, IDA* search, minimax search, alpha-beta pruning. Basic understanding of recursion and Java data structures (list, array, queue) is recommended.

Course series (released as different courses, some might still be unreleased):

  • Part I: Boggle solver (3 different solutions, primary focus is DFS)
  • Part II: N-puzzle solver (4 different solutions: DFS, BFS, A*, IDA*)
  • Part III: Connect Four (4 different AI players: random, Monte Carlo, minimax, alpha-beta pruning)
  • Part IV: Diamond Dash (we will build a bot to beat this Facebook game)

By the end of each course you will build a working solution (or even multiple solutions) which you could continue to work on, update, modify, experiment!

What are the requirements?

  • Basic Java knowledge
  • Understanding of basic data structures (array, list, queue)
  • Basic grasp of recursion
  • Read a thing or two about depth-first and breadth-first searches

What am I going to get from this course?

  • Learn to use searching techniques in practice (this part is mostly about DFS)
  • Build a solver for Boggle game (in 3 different ways)
  • Get a project prototype to work on and develop it further

Who is the target audience?

  • Someone who is familiar with basic algorithms and data structures
  • Java beginners who want to progress further
  • Java beginners who seek some practical projects
  • Java beginners who are eager to learn and experiment
  • Anyone else who is interested in the topics covered

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.


Section 1: Introduction
Boggle game description and rules
Expected result at the end of this course
Where to play Boggle
Section 2: Preparing to solve

Before we start working on our solvers we need a skeleton of our program to be able to handle user's input, convert that that input into game entities and prepare everything for the solver to work with


Our main entity we are going to work with is a board. We need to represent it in a convenient way so that it doesn't bring us any problems in the future.


We want our user to supply a board in a very simple way to make his life easier. And this input has to be converted to our board representation so we can work with it in all future episodes.

Solver basics and user's input
3 questions
Section 3: DFS Solver

We are going to have a look at abstract code which will explain how our first solution is going to work using depth-first search. A very nice step by step example will make it easier to grasp the contents if you have problems understanding the abstract code.


In order to make decisions whether the given word is valid or not we need to check if it is contained in the dictionary. There are many different dictionaries out there. We have some constraints on the dictionary and therefore provide a way of getting a dictionary that requires almost no work to clean it up so that it fits for our purposes.


Every single solver will need the ability to read a dictionary and get the list of words from it. We are going to build an abstract class which will provide a method for our solvers to use to get the dictionary words easily.


Before solving the game we need to set everything up: read the dictionary file, setup all the variables which are going to be needed during the search, declare the method we are going to use as a core search method.


We are going to build a core of our depth-first solver which is going to generate all possible words which can be found on the given board.


We are going to execute our first solver to see how it performs. We are going to verify it using a real game.

DFS solver basics
3 questions
Section 4: Dictionary Solver

Another solution is going to be presented to show you how we can approach the same problem from a different angle.


Once again we are going to build the infrastructure of our solver to set everything up that is needed for our new solver to function well.


The core of our second solver that is going to go over the whole dictionary and try finding each word on the board.


It is time to execute our second solver and compare the results with the first one.

Dictionary solver basics
2 questions
Section 5: DFS Solver using Trie

We are going to point out the problems with the first solver and propose another solution that is going to be based on our first solver but will try to fix its bottlenecks.


For our third solver we are going to use a data structure named Trie. This episode contains all the information you need to understand how it works, how it is built, how it is queried for the information that we need.


We start building our Trie data structure. The overall functionality is described via methods we need.


We are going to fill in the gaps in our Trie data structure to make it work in a way that we require it to.


For the final time we are going to set everything up for our last solver. We need to prepare our Trie data structure before we start using it.


The core of our final solver that is going to be based on the first solver but will add extra pruning which will help us to avoid generation of many useless words (which are not valid)


It is time to compare our final solver with the others. We are going to run it against the real game and then try to find a limit at which it works very well.

DFS solver using Trie basics
2 questions
Section 6: Final words
Where to go from here

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Konstantin Saveljev, Software Developer

I have been dealing with software development since 2001. I am currently in pursuit of Master's Degree in Computer Science. For most of the projects at work I have been working with Java and Scala. In my free time I like to work on small projects in different languages which include Ruby, JavaScript, C/C++, Haskell.

During my first year at the university I became interested in learning algorithms and competing in different contests which required algorithms knowledge. Since then I have participated twice in ACM ICPC as a part of our university team. I'm constantly solving problems on UVa online judge having nearly 1000 problems solved. Algorithms can be very interesting when presented in the right way. Games are definitely one of those right ways to show those eager to learn how something works to solve a game or play against human at good level.

Ready to start learning?
Take This Course