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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:00:48+00:00 2026-06-01T20:00:48+00:00

I’m writing a project for a Python coding class and I have a question.

  • 0

I’m writing a project for a Python coding class and I have a question. I’m writing a Reversi engine that will look several moves ahead in a game and then pick the move that it thinks is best. While I understand that python isn’t an ideal language for this (because it’s not as fast as some other languages), I think that it’s possible to write code that is at least functional while still maybe being a little slow.

That being said, I am in the process of trying to create two tables: a game board (think a matrix) and a game tree that will hold integers. I want to use something memory-efficient and fast to append, delete, and read entries.

The board that I am using right now is not very efficient. I wanted to ask what modules anyone would suggest (with instructions on how to use them) to write something that would make an equivalent of this but lighter on memory (examples: array, numpy; except I don’t know how to use either of these):

self.board = [[0, 0, 0, 0, 0, 0, 0, 0,],
              [0, 0, 0, 0, 0, 0, 0, 0,],
              [0, 0, 0, 0, 0, 0, 0, 0,],
              [0, 0, 0, 1, 2, 0, 0, 0,],
              [0, 0, 0, 2, 1, 0, 0, 0,],
              [0, 0, 0, 0, 0, 0, 0, 0,]
              [0, 0, 0, 0, 0, 0, 0, 0,],
              [0, 0, 0, 0, 0, 0, 0, 0,]]

For the game tree I have ideas depending on how lightweight a list of lists should be. An idea that I’m working with written in standard python is similar to:

tree_zero = %

tree_one =  [%, %, %]

tree_two = [[%, %, %], [%, %, %], [%, %, %]]

tree_thre = [[[%, %, %], [%, %, %], [%, %, %]],
             [[%, %, %], [%, %, %], [%, %, %]],
             [[%, %, %], [%, %, %], [%, %, %]]],

tree_four = [[[[%, %, %], [%, %, %], [%, %, %]],
              [[%, %, %], [%, %, %], [%, %, %]],
              [[%, %, %], [%, %, %], [%, %, %]]],

             [[[%, %, %], [%, %, %], [%, %, %]],
              [[%, %, %], [%, %, %], [%, %, %]],
              [[%, %, %], [%, %, %], [%, %, %]]],

             [[[%, %, %], [%, %, %], [%, %, %]],
              [[%, %, %], [%, %, %], [%, %, %]],
              [[%, %, %], [%, %, %], [%, %, %]]]]

Where each % would be one of the boards given above (and is more than ideal: not every turn has exactly three options). But this is a slow and heavy object that is difficult for python to use memory-efficiently (especially if I go deeper than 4-ply).

If anyone has worked with programs like this before or has ideas of efficient modules to import let me know!

For an example of a game tree, think of the wikipedia page and especially the first picture on the page.

EDIT: Ideally, I would like to look further than four moves ahead, this is just an example of how the first four levels would look. Also, there will be multiple copies of the given trees floating around for use. Speed is important for something that grows exponentially like this.

  • 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-01T20:00:50+00:00Added an answer on June 1, 2026 at 8:00 pm

    In my opinion, Python is utterly perfect for this sort of work! That is, I had a tremendously fun and productive time doing AI for a board game using Python.

    My first recommendation is to explore Bit Boards. Though the application example here is for chess, the concept is perfectly transferable to Reversi. Using zeroes and ones to represent the presence of pieces on a set-sized board not only has the advantage of lower memory footprint, it has the advantage of increased speed of calculating (bitwise operations are faster than equality ones).

    In addition, you should redesign your model to somehow implement recursion (facilitated by a scoring function). Such an implementation means you can write a single function and allow it to scale infinite move depth (or rather, unlimited by your design, limited only by resources) rather than anticipate and hard-code the logic for 1,2,3,4 moves. A well-designed function to this effect works for both sides (players) and can then be halted to choose the best options that fit within a threshold (halted by any criteria you choose, positions calculated/real-time spent).

    For reference, here is the github for a board game called Thud I made with almost exactly the same requirements as your program. Here, I worked with a 17×17 board, three different pieces and two different strategies–which we both can see is already more complex than Reversi’s rules.

    Oh, and a good recursive model also accommodates multi-threading!

    • 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 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
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
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.