thanks for the long reply

and thanks expecially for the tip that there are no constructors. as I said, I think I might have screwed up a little yesterday.

indeed I am working on a chess system.

I already have the starting position and implemented the basic moves a piece can do, as well as castling and en passant.

now to write an AI I check how many possible moves there are for White by selecting a piece which will then move the fields upwards onto which it can go and return the number of those fields. then I deselect the piece again and select the next one. adding those numbers together results in 20 possible moves from the starting position.

this means that I then need 20 copies of the starting position for which I will each select a different move, transforming the copies into move-possibilities.

at this point the “tree” has 20 leaves directly after the root node.

then I call the funtion to also build such a tree for each of the leaves, turning them into nodes and resulting in 400 leaves because Black has the same 20 movement options in the 2nd step as White has in the 1st.

after that, the number of possibilities for the 3rd move varies, depending on the prior moves, so I dont know the exact number of leaves then.

for the 4th move there are then 64 ways for each combination of 2 white and 2 black pieces that were movable from the 1st turn alone to result in the same position.

for the pawns and knights this means there are 46*46=2116 combinations. multiplied by 64 this results in 135424 copies of which only 2116 would be needed. for this example I’d estimate the total amount of possible moves at about 20*20*30*40=480,000.

(135424-2116)/480000=0,277725 => 27.8% of all so far calculated possible moves are unnecessary copies which could be molten together by having 64 nodes point to the same leaf.

for the 6th move there would be even more ways for each combination of 3 white and 3 black pieces but of course also at a generally higher amount of possibilities, and so on…

my plan is to build a tree with a depth of about 6 to 10 moves at the very beginning of the game (depending on how much my computer can handle). as White then make his 1st move, the possibility which is chosen out of the 20 becomes the new root node while the other 19 possibilities from the old root node can be deleted, resulting in a massive cut-off of the tree. at the same time, however, a function is called to make the current leaves into nodes by adding 1 new depth layer again.

I thought about limiting the amount of possibilities which are calculated per second (or frame) to a certain number in order to prevent lag. it might take a little longer for the program to finish the calculation then but as it will also be “thinking” while the player is at turn this should minimize the amount of time the AI needs to “think” while it is at turn.

then of course the possibilities need to be rated.

since I dont need to write the most brilliant AI in the world, I thought about doing something simple which, on a side-note, might result in the AI being a little aggressive but that’s okay:

capturing pieces from the player will of course result in points for the AI while having pieces captured will result in negative points.

I am thinking about values such as

5 - pawn

knight/bishop - 15

rook - 23

queen - 45

king - 10,000

I know some sources suggest values of about 1/5 of these but I also thought about giving 1 to 10 points for putting the enemy king into chess, depending on how many enemy pieces there are to protect the field onto which the AI plans to move in this possibility.

the added values a leaf + the nodes on the way to it are then returned to the root for every single leaf.

using insertion sort I would then create a sorted list of which the best possibility is chosen.

alternatively this also leaves room to implement a strength level by having the AI select a path which e.g. only has about 80% of the maximum points (unless it’s >9,000 of course because that would mean the player’s king can be captured which should not be ignored).