Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7644873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:47:39+00:00 2026-05-31T09:47:39+00:00

I am programming an AI for a chess-like game, based on two types of

  • 0

I am programming an AI for a chess-like game, based on two types of pieces on a 8 x 8 grid.

I want to build a kind of minmax tree, which represents each possible move in a game, played by white players in first, and by black players in second.

I have this generate() method which is call recursively. I need to be able to display about 8 levels of possible moves. Without optimization, this three has 8^8 leafs.

I implemented a simple system which determinate if a grid has actually ever been calculated and if its the case, system just points a child to the ever-calculated child reference.

I don’t know if my explanations are clear, I will join a part of code that you should be able to understand.

The problem is that actually, I am able to generate about 3 or 4 levels of all possibilities. I am far of 8.

I would like to be able to calculate it in less than 5 seconds..

So guys, do you see a solution for optimize my algorithm ?

This is the generate function:
leftDiagonalMove(), rightDiagonalMove() and frontMove() return false if a move is illegal or move the piece in the grid and return true, if the move is legal.

clone() creates a new instance with the same properties of it’s “parent” and backMove() just step back to last Move.

public void generate(Node root, boolean white, int index) {

    Grid grid = root.getGrid();

    Stack<Piece> whitePieces = grid.getPiecesByColor(WHITE);
    Stack<Piece> blackPieces = grid.getPiecesByColor(BLACK);
    Node node;

    String serial = "";
    // white loop
    for (int i = 0; i < whitePieces.size() && white; i++) {
        Piece wPiece = whitePieces.get(i);

        if (grid.leftDiagonalMove(wPiece)) {
            serial = grid.getSerial();
            if(!allGrids.containsKey(serial)){
                node = new Node(grid.clone());
                node.setMove(grid.getLastMove());
                root.addChild(node); // add modified grid
                allGrids.put(serial, node);
                //actualGrid.display();
                if (index < 5 && grid.getPosition(wPiece).x > 0)
                    generate(node, !white, index + 1);
                actualGrid.backMove(); // back step to initial grid
            }
            else{
                root.addChild(allGrids.get(serial));
            }
        }

        if (grid.frontMove(wPiece)) {
            // same code as leftMove
        }

        if (grid.rightDiagonalMove(wPiece)) {
            // same code as leftMove
        }

    }

    // black loop
    for (int i = 0; i < blackPieces.size() && !white; i++) {
        Piece bPiece = blackPieces.get(i);

        if (grid.leftDiagonalMove(bPiece)) {
            // same code as white loop and replacing wPiece by bPiece
        }

        if (grid.frontMove(bPiece)) {
            // same code as white loop and replacing wPiece by bPiece
        }

        if (grid.rightDiagonalMove(bPiece)) {
            // same code as white loop and replacing wPiece by bPiece
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:47:40+00:00Added an answer on May 31, 2026 at 9:47 am

    You need to use something called AlphaBeta pruning on your generated MinMax trees of moves. More on this here:
    http://en.wikipedia.org/wiki/Alpha-beta_pruning
    http://www.progtools.org/games/tutorials/ai_contest/minmax_contest.pdf

    Basically you do one level of branches and then using pruning you eliminate bad branches early. Then from the non eliminated branches you calculate (for each) another level. You prune again until you reach a desired depth.

    Here are a few more links for you to read up on minmax:
    1. http://en.wikipedia.org/wiki/Minimax
    2. MinMax trees – when Min can win in two steps

    This one is on optimizing pruning for chess games:
    1. http://en.wikipedia.org/wiki/Alpha-beta_pruning#Heuristic_improvements
    2. http://en.wikipedia.org/wiki/Refutation_table#Related_techniques

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm programming a King Chess game on the iPhone. When the user touches a
Im programming a little game where two Players have to click some Buttons it
Programming for my Arduino (in some kind of mix of C/C++), I noticed something
There are 4 months since I stopped developing my Silverlight Multiplayer Chess game. alt
Hi I have been learning Java Swing for creating a chess game to practice
Programming in C#.NET 4.0 is my latest passion, and I would like to know
Programming in a sense is easy. But bugs are something which always makes more
I'd like to start developing a "simple" game with HTML5 and I'm quite confused
When programming in CDC I'm always reinventing the wheel, re-implementing stuff like Arrays.toString(Object[]) .
implementing code for customized mini(less squares, less pieces ) chess board in java or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.