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 8297625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:28:57+00:00 2026-06-08T15:28:57+00:00

I’m at the start of creating a chess engine. When I created a function

  • 0

I’m at the start of creating a chess engine. When I created a function that checks if a move is legal, first I had to make the move and then check if the move had put my king in check and then unmake it.

After giving some thought on how to make a function that unmakes a move, I decided it’s much simpler to just copy the board and make the hypothetical move on the copied board, so it doesn’t change the original board structure at all.

But I’m worried this might be a bad idea because when I get to the AI part, as I have to copy the board completely, and it might slow down my engine. Is it so? Could you please share your thoughts about this, since I don’t know much about algorithm complexity and that kind of stuff.

Thank you.

  • 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-06-08T15:28:59+00:00Added an answer on June 8, 2026 at 3:28 pm

    As you say, copying the whole board is likely to slow things down quite a bit. I suggest making an undo list, to which you add the reverse of every move you make. Then to undo, simply repeatedly pop moves off the list and apply them until the list is empty. This way your AI can explore all the possibilities by using a simple recursive function with a maxdepth parameter.

    Re: Bo’s Comment

    I respectfully disagree.

    For programs written in lower-level languages a board copy may amount to a single memcpy, and then it might very well be faster. But for an object orientated python program, where there’s one object per chess piece, plus metadata, a fully independent game state copy is almost certainly much slower than creating a single new “undo” object and adding it to a list.

    Mind you, this has little to do with the size of the structure, and more with the number of operations required to copy that structure. Especially in python, function calls add a significant amount of overhead. According to this answer (my own), instantiating 32 piece objects in CPython is equivalent to 83 function calls, and that is presuming they do not have any subclasses other than object. Then the data allocation and copying comes on top of that.

    If the board had been a 16×16 numpy array, I agree a board copy might be faster.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Specifically, suppose I start with the string string =hello \'i am \' me And
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.