Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views46 pages

Programming A Mini Chess in Phyton

Uploaded by

ljt122333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views46 pages

Programming A Mini Chess in Phyton

Uploaded by

ljt122333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Table of Contents

Table of Contents ........................................................................................................................................................................1


1. Preface.....................................................................................................................................................................................2
2.Pico Chess program-„mini“ means „|4+5|chess“ .....................................................................................................................3
How is "| 4 + 5 | Chess" constructed? - Chess on 20 fields...................................................................................................3
Chess field display - "| 4 + 5 | Chess"....................................................................................................................................3
3.Figure field representation .......................................................................................................................................................4
Figure field representation in the computer ................................................................................................................................4
4.Offset-step ................................................................................................................................................................................5
A construction plan - which "program components" has | 4 + 5 | chess?..............................................................................5
Field input and output............................................................................................................................................................5
5.The „Move-Maker“..................................................................................................................................................................6
The „Move“-generator - the recipe for the solution ..............................................................................................................6
6. Count chess material ...............................................................................................................................................................7
Counting chess material - yes he can! ...................................................................................................................................7
He‘s satisfied with a “draw”..................................................................................................................................................7
Mini chess tree - "maximize and minimize" - prevent the worst ..........................................................................................7
7. Mini chess tree ........................................................................................................................................................................8
8.Chess tree shown graphically...................................................................................................................................................9
Chess tree graphical - "the thought experiment of | 4 + 5 | chess" .......................................................................................9
9. The chess program gets a chess ............................................................................................................................................10
| 4 + 5 | Chess gets a chess "a look into the future".............................................................................................................10
10. TEST THE "TIGER" - A MATCH WITH | 4 + 5 | CHESS................................................................................................11
11. Move 2 + 3 ... diagram ........................................................................................................................................................12
12. Move 4 ... diagram ..............................................................................................................................................................13
13. Move 5 + 6 ... diagram ........................................................................................................................................................14
14. Move 7 + 8 ... diagram ........................................................................................................................................................15
15. Move 8+9...diagram ............................................................................................................................................................16
16. Move 10 : Chess programming is actually great fun. .........................................................................................................17
Conclusion ...........................................................................................................................................................................17
17. Program improvement.........................................................................................................................................................18
Program worsening improvement-oh yes sure!...................................................................................................................18
18. Python some important instructions....................................................................................................................................19
| 4 + 5 | Chess and Phyton- "look at the experiment" ..........................................................................................................19
19. Phyton “loops” ....................................................................................................................................................................20
20. Phyton “list” ........................................................................................................................................................................21
21.Phyton sort ...........................................................................................................................................................................22
22.Copy Python lists .................................................................................................................................................................23
23.Phyton „maximum“..............................................................................................................................................................24
24.Phyton „random“..................................................................................................................................................................25
The computer simply calculates "randomly".......................................................................................................................25
25. Phyton „random.choice“ .....................................................................................................................................................26
26. Phyton Code |4+5|CHESS...................................................................................................................................................27
Program code "| 4 + 5 | Chess" in Python............................................................................................................................27
27. Appendix time and sky........................................................................................................................................................42
An oversized place ....................................................................................................................................................................42
A gift .........................................................................................................................................................................................43
Dimension of horror ..................................................................................................................................................................44
There is hope .............................................................................................................................................................................44
28. The valuable time ................................................................................................................................................................45
29.imprint ..................................................................................................................................................................................46

Programming a mini chess in phyton 1


1. Preface

Pico means something like "trillionth" - that is very small.


The workload for programming a “chess program” on 64 fields is very large. So the
author decided to program a very small chess on 20 fields, so to speak, as an "experi-
ment" without any special requirements. Phyton was used as the programming lang-
uage. The aim of this project was to roughly understand the "construction principles"
of the construction plan of a chess program. The current state of knowledge of chess
programming is only rudimentary at | 4 + 5 | Chess. Rather, the program is its
own "programming creation". (All images are labeled in German)

„ Pico-Schach“

Do we all have time in the “world”? The subject of “Time and Heaven” is covered in
the “Appendix” of this book.

With this in mind, I wish all readers a lot of fun with programming.

Gerald Wartensteiner

Programming a mini chess in phyton 2


2.Pico Chess program-„mini“ means „|4+5|chess“

Pico means something like "trillionth" - that is very small. The amount of work involved in programming
a “chess program” on 64 fields is very large. So the author has made up his mind. To program a very small
chess on 20 fields, so to speak, as an "experiment" without any special requirements. Phyton was used as the
programming language. Goal of this project it was the "construction fundamentals" to roughly understand the
blueprint of a chess program. The current state of knowledge of chess programming is only rudimentary
at | 4 + 5 |Chess. Rather, the program is its own "programming creation".
For a long time the author was moved by the question: "How does the chess computer make its move".
What is the secret of the chess programs? Unfortunately there is almost no literature on this Theme. It is also
only possible to program already with a very high expenditure of time „Understand“ existing chess programs.
Sometimes the programmers work studied computer scientists or mathematicians for years on a good chess
program. You can't live from it. Only the writers of top chess programs can dated Sell ​the software live.

How is "| 4 + 5 | Chess" constructed? - Chess on 20 fields

| 4 + 5 | Chess is played on a 4x5 field. The farmers can move forward one space at a time. If the pawns have
reached the baseline, they are automatically converted into a queen. The towers and the queen as well as the
king are present on figures.
The pieces are set up according to "Silverman 1981", a chess variant, whereby all chess rules apply - with the
exception of castling and the double pawn step.

Chess field display - "| 4 + 5 | Chess"

Knight and bishop are missing in | 4 + 5 | Chess. The edge fields are assigned a number in the course of chess
programming. For | 4 + 5 | ChessJ this is the "2".

Programming a mini chess in phyton 3


3.Figure field representation
Figure field representation in the computer

Figure field represented by numbers.

The pieces are represented in the chess program with numbers. In our case, the ones (1) stand for the black
pawns. Four (4) represents the black rooks, 8 represents the black queen and 9 represents the black king. The
negative numbers, i.e. the minus ones (-1), stand for the white pawns. The number -4 represents the white
rooks, -8 stands for the white queen and -9 is the substitute number for the white king. The empty fields are gi-
ven a zero (0). These numbers also roughly represent the material value. The material value of the lady is obtai-
ned alternatively by two towers (2x4 = 8). The pawns have a material value of one (1 = one pawn unit). If you
add up all the black numbers you get the material value plus 29 for the white side, the opposite is the material
value for the black pieces, i.e. minus 29. The 4x5 chess field is surrounded by twos (2). These two are used for
programming.

Array Offsets

You also need an array. This array can be looked at like clear paper with numbers which is exactly above the
figure field. The Moving figures. Above the number -4 in the figure field is the number 31 in the array. So if the
-4 (rock white) is moved, the -4 can be the white rock from the array 31-25 and 31-19, 31-13 and so on. 31-
7drive. The individual driving options or steps can be easily calculated.
The black rock moves from array no. 7 to array no.13 exactly 13-7 = 6 steps, so that's the
black rook advanced one space. These driving possibilities of the figures are called offsets. At the same time the
black rock can move to the right, i.e. from array number 7 to number 8
for this he needs 8-7 = 1 which corresponds to an offset step. The drawing with the arrows
shows this. So white rock to the left corresponds to an offset step of -1.
White rock to the right corresponds to an offset step from 1. Rock down corresponds to
6 and up the -6. These offset steps apply to both white and black.
For the direction of travel of the queen, the diagonal directions also apply, i.e. after
diagonally above below -5 and 5. Arrow direction to the left (offset +7) corresponds to, for example
Moving the queen from square 8 -15.

Programming a mini chess in phyton 4


4.Offset-step

Figures offset steps as follows: Offset-steps


Rocks : 1, -1, 6, -6
Queens: 1, -1, 6, -6 and 5,-5,7,-7
Kings : 1, -1, 6, -6 and 5,-5,7,-7
White Pawn : -6,-7,-5
Black Pawn : 6, 5,7
These offset steps e.g. So towers repeat themselves 7+6=13+6=19+6=25+6=31
It is 7,6,19,25,31 the first column in the array. These numbers can be calculated using offset steps.

A construction plan - which "program components" has | 4 + 5 | chess?

Component overview:

 Field input and output


 Move „maker“
 Mini chess tree with integrated material evaluation function

Field input and output

The field input and output is done with the program parts array and figure field representation
carried out as described above. The necessary calculation operations can now be transferred to the Phyton
programming language on the basis of the theoretical considerations.

Programming a mini chess in phyton 5


5.The „Move-Maker“
The „Move“-generator - the recipe for the solution

The move generator calculates all possible moves of the white stones and all
Moving possibilities of the black stones.
The move generator calculates the movement possibilities for the black tower
according to the recipe as follows:

 Determine the position of a black tower (which array number is it on)


 Drive all possible tower moves up, down, left, right
 with the help of the offset steps and consider the following:

1. If the field is empty, ie "zero", save the move.


Possible moves are for example [7-13, 7-19, 7-25] if none
Black pawn on 13 or your own black piece.
2. If the field with a number less than "zero" (-1, -4, -8, -9) is occupied by the opponent, then
save take the move, but do not go into a space behind it.
3. If there is a piece of your own on the field (number greater than zero 1,4,8,9) the move is not
saved.
4. If the edge is reached, i.e. the field value 2 is reached - abort the operation.
5. Repeat these processes for the second black rook.
6. For the towers and the ingredients such as the queens, the pawns, the kings, repeat the above
recipe taking into account the offset steps.

Practically it looks like this - in the program the „moves“ are collected in a list, for example the rock moves in a
rock move list. At the beginning the computer saves the rock moves = [] as an empty list. After executing the re-
cipe are possible rock moves in a list as follows: [7,13,7,19,7,25]. Please note that these moves are "pseudo-
legal", i.e. illegal king moves are also saved. These will then be dealt with separately later.
Finally, all black moves are separated from the white in one List collected, the same is done with white moves.
It looks like this, for example:

The example is a move list for "Black", the numbers are separated by commas.
"Black" can therefore drive from field 21-26 and from field 10 to field 9 etc.
As you can see, such a move generator is a lot of work. That is also important
it works flawlessly, it should have the right moves in every chess position
determine for "white" and "black".

Programming a mini chess in phyton 6


6. Count chess material
Counting chess material - yes he can!

The so-called "material value count" is also important. The computer makes internal moves in the program (in your head,
so to speak) and calculates the material value of the position for each move.
The material value is very easy to calculate. The individual material values ​of the red figures (black) are added together. If
the red (black) side still has a rook and a pawn and the king as well, then the material value is 4 + 1 + 8 = 13. In return, the
material value of the blue (white) figures is calculated. For example, if blue (white) has a rook and a king, the material va-
lue is -4 + (- 8) = -12. The material difference is 1, i.e. the red (black) side is one point ahead. Now the computer anticipa-
tes all possible red (black) moves and calculates the material value for the moves. At the same time, all possible response
moves on the blue (white) side are calculated in advance. The computer thinks: "If I drive with the red (black) queen from
field 8 to field 32, what answer options does the blue (white) side have and what is my material value and that of my op-
ponent". In order to find out, all possible moves are carried out on a trial basis and the material value of the "chess posi-
tion" and the associated position image (chess diagram) are calculated. In this case, the difference in material is interes-
ting, so if I were to drive from field 8 to field 32 and my opponent makes all possible moves, how big are the material diffe-
rences? Likewise, if I were to drive the pawn from square 15 to square 21, the computer asks itself, which answer moves
would my opponent have and how big are the material differences? This difference is calculated for all possible moves.

He‘s satisfied with a “draw”

The representation shows possible moves in the form of a "chess tree". The square boxes are called nodes. All X, Y, Z stand
for possible moves of red, whereby not all possible moves are shown. Possible moves are, for example, the red pawn mo-
ve 15-21 or the queen move 8-32. Possible answer moves from blue are rook 31-32, pawn 28-21, queen 32-8 and other
moves that cannot be seen in the tree. The computer has the red pieces and always chooses the move that has the smal-
lest material difference to blue, so the computer plays a draw.
(He spares the human opponent). As can be seen from the illustration, he selects the move with the material difference of
0 for this purpose, namely queen from square 8 to square 32. The computer writes the material differences in the Dif list
(difference list ), he writes possible moves in the move list, and he writes the material differences in the MiD list.

Mini chess tree - "maximize and minimize" - prevent the worst


The following train list is given. Black (red) can drive as follows:

So the first possible move is from fields 8-32 etc. as in the above move list of the computer
cited. The computer now executes and calculates all moves with the help of the move generator

Programming a mini chess in phyton 7


7. Mini chess tree

for each move the points of the material. Simply the numbers 4 + 8 + 9 + 4 + 1 + 1 + 1 that results in the
Material sum of "black" (red) is 28 for this position. All possible at the same time
Counter-moves of the "white" (human) are calculated and the material sum for "white" is determined.
For this position, all possible moves must be calculated and evaluated.
At the same time, the material differences (Dif) of the chess positions “black” (red) and “white” (blue) are cal-
culated.

The queen move (red) from fields 8-32 is carried out on a trial basis and the material sum is calculated,
that is 28. Now all white answer moves are calculated and the material difference is determined.
If "black" has fewer material points after the white counter move, these differences are entered in the list of
differences. If “White” (blue) takes the queen with the rook, “White” also has 28 points. The material diffe-
rence between “black” (red) and “white” (“blue) is therefore zero (28-28 = 0).
This is stated in the difference list (Dif =) with the empty list [] in the first position.
The computer now calculates the maximum of all material differences, see list of differences (Dif).
So he looks for the maximum of [1,8] that is 8, as well as of [8,8] that is again 8 and from zero [],
so nothing - that is []. He writes these maximum values in the MiD list.

He looks for the smallest number (minimum) from the MiD list, so that is [] means zero.
The zero [] is in the 1st position in the MiD list, so he makes the 1st move from the move list (move):

Moves „run on a trial basis“

White (bl) can only reach the next move see point differences
Black (ro) chooses the
move where white can achieve the least = minimum >
first entry in the list is minimum

Programming a mini chess in phyton 8


8.Chess tree shown graphically
Chess tree graphical - "the thought experiment of | 4 + 5 | chess"

The moving possibilities are carried out on a trial basis and the material difference is calculated

BLUE can only reach the next move see "Difference"

RED chooses the move where blue can reach the least = minimum, hence queen 8-32
The double underlined line shows the material difference in the positional images after the move from "BLUE".
This is "zero" so 0 = [], and 1 and 8 = [1,8]. If you look at the Dif list, these differences are in the list. The computer (RED)
selects the LEFT OF THE SOLUTION which has the smallest material differences after the counter-move of "BLUE". There-
fore he chooses the move Queen 8-32. For the right side of the subtree, the computer calculates a material difference
of 1 or 8, for the draw option pawn 15-21. Since 1 or 8 is greater than "zero", he discards this option. He also examines
the possible moves 16-22, 8-14, 8-20, 8-26, 9-14 - the difference in material between these moves is greater than "zero",
so this is of no interest for the time being.
It should also be mentioned that he tests and calculates all possible moves on level 1 and level 2.
Programming a mini chess in phyton 9
9. The chess program gets a chess
| 4 + 5 | Chess gets a chess "a look into the future"

| 4 + 5 | Schach is looking into the future with two half moves. That corresponds to a mini chess tree
with a very simple material evaluation function, so | 4 + 5 | Chess
even just about a “mini” chess knowledge.

Another example is a human “check” with the rook


What does | 4 + 5 | Chess do?

Testing „Moves“

White (bl) can only reach the next move see point differences

Black (ro) chooses the move where white can reach the least = minimum

In the dif-list there is mainly the number 9, i.e. 9 points difference between what the
Material value corresponds to the king. The computer can also lose the "king",
it can be captured on the next move. The only alternative is escape field 7
The computer selects the minimum from the MiD list, which is the empty list [], ie zero.
The zero [] is in fourth position in the MiD list, so the computer chooses from the
Move list (move) the fourth move, i.e. 8-7, this move is made.
| 4 + 5 | Chess is still imperfect - full of "bugs", an experiment, so to speak,
for this reason a comment section has been implemented.
So "| 4 + 5 | ChessJ" adds its mustard with every move.
The reader may find this sometimes more or sometimes less pleasant.
For demonstration purposes, a game with | 4 + 5 | Chess follows

Programming a mini chess in phyton 10


10. TEST THE "TIGER" - A MATCH WITH | 4 + 5 | CHESS
As the following game of chess proves, my little 2 ply chess program is already there
able to play chess. The stupid mistakes of "humans" are of course planned to
determine whether | 4 + 5 | chess can gain a game advantage from these mistakes.

MOVE 1: The author [knows] drives with the „pawn“

MOVE 1: The | 4 + 5 | chess takes the pawn, which results in a point material advantage

MOVE 2: The author takes the „pawn“

Programming a mini chess in phyton 11


11. Move 2 + 3 ... diagram

MOVE 2: The | 4 + 5 | chess takes the queen, so the program has 8 points more

MOVE 3: The author takes the queen of | 4 + 5 | chess with the rook, therefore equalizing points

MOVE 3: The | 4 + 5 | chess moves the pawn up one space

Programming a mini chess in phyton 12


12. Move 4 ... diagram

TRAIN 4: The author occupies the 4th row with the „rock“

MOVE 4: The | 4 + 5 | chess takes the pawn and gives chess

Move 5: The author tests how | 4 + 5 | chess reacts when he plays "very stupid"

Programming a mini chess in phyton 13


13. Move 5 + 6 ... diagram

MOVE 5: | 4 + 5 | Chess moves the pawn forward one space on the d-row

MOVE 6: The author "gives away" his "rock", the gift is not accepted

MOVE 6: | 4 + 5 | Chess takes the white pawn and gives a "check"

Programming a mini chess in phyton 14


14. Move 7 + 8 ... diagram

MOVE 7: The author captures the pawn on c2 with the king

MOVE 7: The | 4 + 5 | chess transforms the pawn into a queen and gives "chess"

MOVE 8: The author takes the black queen with his white king

Programming a mini chess in phyton 15


15. Move 8+9...diagram

Move 8: | 4 + 5 | Chess [black] wants to swap the “rooks”

MOVE 9: The author comfortably moves one field forward with the white "rock"

MOVE 9: | 4 + 5 | Chess takes the white rook, so his material advantage is 8 points

Programming a mini chess in phyton 16


16. Move 10 : Chess programming is actually great fun.

MOVE 10: The author takes the rook from | 4 + 5 | chess with the king

MOVE 10: Finally, the program "| 4 + 5 | Chess" takes the white pawn, thus
the material advantage of black [| 4 + 5 | chess] is a total of 14-9 = 5 points.

Conclusion

As expected, the program has always sought a “material advantage”.


Only on move 6 did the | 4 + 5 | chess program not take the given rook,
but given an intermediate check.
Chess programming is actually great fun.
The author has thereby get a little insight into the "way of thinking" of the chess computer.

Programming a mini chess in phyton 17


17. Program improvement

Program worsening improvement-oh yes sure!

As my first hobby chess program, | 4 + 5 | SchachJ is not yet perfect. There is still a lot
to improve. So sometimes there are several good moves, but the program chooses
always select the first move from the MiD list. Another evaluation function could be used here
programmed to solve this problem.
Also, the royal security is not guaranteed in every case, from time to time it arises
the king went illegally into chess to the amusement. The author has these problems
already solved on the other hand, the reader of these lines should have fun programming,
so that would be a bit of a challenge.

Such a situation is listed here for demonstration purposes.

According to the MiD list there are two "good" moves - zero is shown in the 1st position of the MiD list
with 2 empty square brackets. However, the zero also appears in the 2nd position on the MiD list.
However, the program always plays the move that comes first on the MiD list
stands, so an additional evaluation function would have to calculate whether move 1 or
Move 2 is better. In the event that the king is in chess, he could have his own „Part“ of the program.

Puzzles solved - chess programs calculate evaluation numbers

Chess programs calculate evaluation numbers. The move with the best
Evaluation number is executed. Chess programming is a numbers game
and functions. There are certain theoretical bases but these were used at
| 4 + 5 | Chess intentionally only partially implemented, so it is an easy one
Explainability guaranteed.

Programming a mini chess in phyton 18


18. Python some important instructions
| 4 + 5 | Chess and Phyton- "look at the experiment"

Phyton is a free programming language which is available under the


Internet address www.phyton.org/download/ can be reached. The program
is free and suitable for novice programmers.
With this programming language you can create your own software applications
develop. The "| 4 + 5 | chessJ" was programmed with Phyton.
For demonstration purposes I have the so-called IDLE below, i.e.
the development environment mapped.( German variables )

This "idle" is intended for trying out a few lines of code.


For “correct programming” it is better to use the “development environment”. To do
this, select "File" with the mouse ... then another menu appears. Select "new
file" here and you can start your own program.

Programming a mini chess in phyton 19


19. Phyton “loops”

The print statement prints out text or numbers.

With a = 12; b = 3 and so on, arbitrary numbers are defined.


If there is a * b after print, this calculation is carried out. The comma
separates text and arithmetic input.

An input statement asks the user to enter a number.


If you give e.g. 5678 and the print instruction, the output is 5678.

The command range (0,10,2) creates a list field from 0 to 10 at a distance of 2,


i.e. in combination with the print statement, the row of two is output.

If you assign x range (0,10,2), the list field (row of two) is called
from now on x. For i in x means that the computer will select every x in the list
should, just me. There are 5 numbers in the list, so this statement becomes
repeated 5 times. The following print i statement prints the row of two.
This is a so-called for loop, i.e. a repetition statement.

The pop () instruction clears the last number in the list. If you put x before pop (),
then the last number is deleted from the list x.

Programming a mini chess in phyton 20


20. Phyton “list”
The command x.insert (1.99) inserts the number 99 at the list index position 1.
I.e. List index 0 = 0, list index 1 = 99, list index 2 = 2, list index 3 = 4 etc.

Print len (x) prints the number of list elements, i.e. 5.

Since the result of len (x) = 5, is 5, the following repetition statement for i in range
(len (x)) is executed five times, where The print i statement prints all five numbers in
the list x.

With x.remove (99) you can remove the number 99 from the list.

Repeat + repeat he can!


The repeat statement (for) below outputs the 7th series from 1-9.

When you define an if query and what the computer does


after if should do so the statement part after the command if is executed.
An if query is to be understood as an “if then” query. In the following
Example is asked "if i equals 3 then". So if i should equal 3
Programming a mini chess in phyton 21
21.Phyton sort

the computer should do something. The break statement on the line below says
from what to do. Break stands for "interrupt". Break the iteration loop when i equals 3.
As a result, the 7 series is only printed up to 3x7.

Sort and break

This code assigns five numbers to the variable field-list. With print the
List printed out.

Then the numbers in the list are sorted, which is what the
Command "feldliste.sort ()" and printed out.

The instruction max (field list) determines the maximum, i.e. the largest number,
min (field list) is the smallest number.

Programming a mini chess in phyton 22


22.Copy Python lists

If you want to copy the list, the command [:] creates a new list.
The copy can be given any name, in our case the list is called
simply "copy".

The keyword append (-345) causes -345 in the example below


is added to the list. The entire command is feldliste.append (-345)

You can of course add several numbers to a list, this is done with
the command feldliste.list.extend (see below). The code example shows the procedure.

If the 2nd number is to be output in the field, write print feldliste [1].
The 1st number in the field is assigned to the expression field list [0].

In the next example, list b is appended to list a with the brackets,


so completely. This is done twice in total, because a.append (b) was entered twice.

Programming a mini chess in phyton 23


23.Phyton „maximum“

Should be the maximum of the list [1,2], which is in the main list a
are determined, this can be done with max ([a4]). The minimum will be
determined with min ([a4]).

If one wants to multiply the first number of the list b, the instruction is
b [0] = b [0] * 2 expedient.

If the list is intended to be deleted, this is done simply by assigning it


an empty list. For example waszumloeschen [:] = [].
Defines the list what to delete as an empty list [].

If the use of random numbers is intended, the instruction is given beforehand


Specify import random. Whole numbers are now with random.randint (from, to)
set. So random numbers from 0-50 are generated with random.randint (0.50).

Programming a mini chess in phyton 24


24.Phyton „random“

The example below determines 10 random numbers between 0 and 50.

If you want to calculate with strings (names, operators), the use of the
"Eval function" makes sense. The instruction eval (`three * four`) calculates 3x4,
if three = 3 and four = 4 are defined. The example shows another
Possible application of eval. A numberA and a numberB become the
Numbers 3.5 and 2.0 assigned in string form. Also an "operator"
defined with times *. The strings are added up, that's done
the command Evaluate = numberA + operator + numberB. Lastly, the expression
calculated by eval (evaluation), i.e. 2.0 * 3.5 = 7.0 is calculated.

The computer simply calculates "randomly"


The last example executes the following statements accordingly:

 Repeat the calculations five times


 Randomly choose a number from the number 1,2,3,4
 Randomly choose a number from the number 0.1,0.2,0.3,0.4
 Randomly pick an operator from *, +, -
 Make a random calculation with the numbers and the operator

Calculate the result and print it out with the print statement.

Programming a mini chess in phyton 25


25. Phyton „random.choice“

This short introduction to the Phyton programming language follows


finally, without further explanation, the program code of | 4 + 5 |chess
(with German variables)
Should the reader enjoy "programming with Phyton", so nothing stands in the way of
developing your own software.

Programming a mini chess in phyton 26


26. Phyton Code |4+5|CHESS

Program code "| 4 + 5 | Chess" in Python


import random
#Feldeingabe
f=[2,2,2,2,2,2,
2,4,8,9,4,2,
2,1,1,1,1,2,
2,0,0,0,0,2,
2,-1,-1,-1,-1,2,
2,-4,-8,-9,-4,2,
2,2,2,2,2,2]
print " ********************* "
print " * 4x5|Schach* "
print " * auf 20 Feldern * "
print " * by GW. 2013 * "
print " * EXPERIMENTSCHACH * "
print " ********************* "
print " mit launigen Kommentaren "
print
print "T->schwarzer Turm + ->schwarzer Bauer"
print "t->weisser Turm * ->weisser Bauer"
print " weiss beginnt "
print
q=[]
for i in f:
if i==3:
q.append('L')
if i==5:
q.append('S')
if i==4:
q.append('T')
if i==8:
q.append('D')
if i==9:
q.append('K')
if i==1:
q.append('+')
if i==0:
q.append('.')
if i==-3:
q.append('l')
if i==-5:
q.append('s')
if i==-4:
q.append('t')
if i==-8:
q.append('d')
if i==-9:
q.append('k')
if i==-1:
q.append('*')
print'Feld 4x5 Feldnummer '
print'***********',' ''***************'
print'*',q[0],q[1],q[2],q[3],'*',' *'' 7 8 9 10 *'
print'*', q[4],q[5],q[6],q[7],'*',' *'' 13 14 15 16 *'
print'*', q[8],q[9],q[10],q[11],'*',' *'' 19 20 21 22 *'
print'*', q[12],q[13],q[14],q[15],'*',' *'' 25 26 27 28 *'
print'*', q[16],q[17],q[18],q[19],'*',' *'' 31 32 33 34 *'

q=[]

print'***********',' ''***************'

voon=0;biis=0
for a in range(1,100):#anzahl der zuge
# hier zugeingabe
Programming a mini chess in phyton 27
voon=input('Feldnummer von-> ')
biis=input('Feldnummer bis-> ')

f[biis]=f[voon]#ausfuehern
f[voon]=0

#print'***************'
#print f[7:11]
#print f[13:17]
#print f[19:23]
#print f[25:29]
#print f[31:35]
#print'***************'
#damverwandlung
if f[7]==-1:
f[7]=-8
if f[8]==-1:
f[8]=-8
if f[9]==-1:
f[9]=-8
if f[10]==-1:
f[10]=-8

q=[]
for i in f:
if i==3:
q.append('L')
if i==5:
q.append('S')
if i==4:
q.append('T')
if i==8:
q.append('D')
if i==9:
q.append('K')
if i==1:
q.append('+')
if i==0:
q.append('.')
if i==-3:
q.append('l')
if i==-5:
q.append('s')
if i==-4:
q.append('t')
if i==-8:
q.append('d')
if i==-9:
q.append('k')
if i==-1:
q.append('*')

print "Mensch von : ",voon,"-",biis

print'***********',' ''***************'
print'*',q[0],q[1],q[2],q[3],'*',' *'' 7 8 9 10 *'
print'*', q[4],q[5],q[6],q[7],'*',' *'' 13 14 15 16 *'
print'*', q[8],q[9],q[10],q[11],'*',' *'' 19 20 21 22 *'
print'*', q[12],q[13],q[14],q[15],'*',' *'' 25 26 27 28 *'
print'*', q[16],q[17],q[18],q[19],'*',' *'' 31 32 33 34 *'
print'***********',' ''***************'
q=[]

#bestimme Bauernpositionen schwarz


bauernpositionschwarz=[]# Bauernposition

Programming a mini chess in phyton 28


bauer=1;x=0
for i in f:
if i==bauer:
bauernpositionschwarz.append(x)
x=x+1
#berechne geradenzug fuer jede Bauernposition
bauernzugschwarz=[];bauernschwarzschlag=[] #Bauerzuege
for i in bauernpositionschwarz:
if f[i+6]==0:
bauernzugschwarz.append(i)
bauernzugschwarz.append(i+6)
if f[i+7]<0:
bauernschwarzschlag.append(i)
bauernschwarzschlag.append(i+7)
if f[i+5]<0:
bauernschwarzschlag.append(i)
bauernschwarzschlag.append(i+5)
# teste fuer turm++++++++++++++++++++++++++++++++++++++++++++++++
turmpositionschwarz=[]#Turmzuege
turm=4;x=0
for i in f:
if i==turm:
turmpositionschwarz.append(x)
x=x+1

su=0 # turmanzahl bestimmen


for turmanzahl in turmpositionschwarz:
su=su+1

turmzuge=[];turmschlag=[]
k=0;ad=0 # dazuzaehlen fuer turmposition
for n in turmpositionschwarz:
for v in range(1,5): #fuer die Richtungen 4x
if v==1:
ad=6 #ad fuer nach unten
if v==2:
ad=-6 #ad fuer nach oben
if v==3:
ad=1 #ad fuer nach rechts
if v==4:
ad=-1
#nach unten suchen
z=0;abbruchwert=0
for i in range(1,5): # ab turmposition schleife z.bsp 4x
z=z+ad
if f[turmpositionschwarz[0+k]+z]!=0:
break
else:
turmzuge.append(n) #von
turmzuge.append(turmpositionschwarz[0+k]+z) #bis
abbruchwert=z
#Restglied dazu wenn unter null=feind
if f[turmpositionschwarz[0+k]+abbruchwert+ad]<0:
turmschlag.append(n)
turmschlag.append(turmpositionschwarz[0+k]+abbruchwert+ad)
# wenn 2 tuerme k anders weil zweiter turm
if su==2:
k=1

# teste fuer dam+++++++++++++++++++++++++++++++++++++++++++++++++


dampositionschwarz=[]#damzuege
dam=8;x=0
for i in f:
if i==dam:
dampositionschwarz.append(x)
x=x+1

su=0 # turmanzahl bestimmen


for damanzahl in dampositionschwarz:
su=su+1
Programming a mini chess in phyton 29
damzuge=[];damschlag=[]
k=0;ad=0 # dazuzaehlen fuer damposition
for n in dampositionschwarz:
for v in range(1,5): #fuer die Richtungen 4x
if v==1:
ad=6 #ad fuer nach unten
if v==2:
ad=-6 #ad fuer nach oben
if v==3:
ad=1 #ad fuer nach rechts
if v==4:
ad=-1
#nach unten suchen
z=0;abbruchwert=0
for i in range(1,5): # ab damposition schleife z.bsp 4x
z=z+ad
if f[dampositionschwarz[0+k]+z]!=0:
break
else:
damzuge.append(n) #von
damzuge.append(dampositionschwarz[0+k]+z) #bis
abbruchwert=z
#Restglied dazu wenn unter null=feind
if f[dampositionschwarz[0+k]+abbruchwert+ad]<0:
damschlag.append(n)
damschlag.append(dampositionschwarz[0+k]+abbruchwert+ad)

# wenn 2 damen k anders weil zweitedam


if su==2:
k=1
#schraege damenzuge ausf?hren
damzuges=[];damschlags=[]
k=0;ad=0 # dazuzaehlen fuer damposition
for n in dampositionschwarz:
for v in range(1,5): #fuer die Richtungen 4x
if v==1:
ad=7 #ad fuer nach unten
if v==2:
ad=-7 #ad fuer nach oben
if v==3:
ad=5 #ad fuer nach rechts
if v==4:
ad=-5
#nach unten suchen
z=0;abbruchwert=0
for i in range(1,5): # ab damposition schleife z.bsp 4x
z=z+ad
if f[dampositionschwarz[0+k]+z]!=0:
break
else:
damzuges.append(n) #von
damzuges.append(dampositionschwarz[0+k]+z) #bis
abbruchwert=z
#Restglied dazu wenn unter null=feind
if f[dampositionschwarz[0+k]+abbruchwert+ad]<0:
damschlags.append(n)
damschlags.append(dampositionschwarz[0+k]+abbruchwert+ad)

# wenn 2 damen k anders weil zweitedam


if su==2:
k=1

damger=[];damschl=[]
damger.extend(damzuges)
damger.extend(damzuge)
damschl.extend(damschlags)
damschl.extend(damschlag)

#bestimme kingpositionen schwarz


kingpositionschwarz=[]# kingposition
king=9;x=0
for i in f:
if i==king:
Programming a mini chess in phyton 30
kingpositionschwarz.append(x)
x=x+1
#berechne geradenzug fuer jede kingposition
kingzugschwarz=[];kingschwarzs=[] #kingzuege
for i in kingpositionschwarz:
if f[i+6]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i+6)
if f[i-6]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i-6)
if f[i+1]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i+1)
if f[i-1]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i-1)
if f[i+7]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i+7)
if f[i-7]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i-7)
if f[i+5]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i+5)
if f[i-5]==0:
kingzugschwarz.append(i)
kingzugschwarz.append(i-5)
if f[i+6]<0:
kingschwarzs.append(i)
kingschwarzs.append(i+6)
if f[i-6]<0:
kingschwarzs.append(i)
kingschwarzs.append(i-6)
if f[i+1]<0:
kingschwarzs.append(i)
kingschwarzs.append(i+1)
if f[i-1]<0:
kingschwarzs.append(i)
kingschwarzs.append(i-1)
if f[i+7]<0:
kingschwarzs.append(i)
kingschwarzs.append(i+7)
if f[i-7]<0:
kingschwarzs.append(i)
kingschwarzs.append(i-7)
if f[i+5]<0:
kingschwarzs.append(i)
kingschwarzs.append(i+5)
if f[i-5]<0:
kingschwarzs.append(i)
kingschwarzs.append(i-5)

schwarzzug=[]#alle zuge sammeln


schwarzzug.extend(bauernzugschwarz)
schwarzzug.extend(turmzuge)
schwarzzug.extend(damger)
schwarzzug.extend(kingzugschwarz)
schwarzschlag=[]#alle schwarzen sammeln
schwarzschlag.extend(bauernschwarzschlag)
schwarzschlag.extend(turmschlag)
schwarzschlag.extend(damschl)
schwarzschlag.extend(kingschwarzs)
gesamtschwarz=[]
gesamtschwarz.extend(schwarzschlag)
gesamtschwarz.extend(schwarzzug)

Programming a mini chess in phyton 31


#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# weiter alle weissen ein


# weiter waehle einen zug und teste ob king geschlagen,retour
#bestimme Bauernpositionen weiss
ausweiss=[]
def weiss():
bauernpositionweiss=[]# Bauernposition
bauerw=-1;x=0
for i in fe:
if i==bauerw:
bauernpositionweiss.append(x)
x=x+1

#berechne geradenzug fuer jede Bauernposition


bauernzugweiss=[];bauernweissschlag=[] #Bauerzuege
for i in bauernpositionweiss:
if fe[i-6]==0:
bauernzugweiss.append(i)
bauernzugweiss.append(i-6)
if (fe[i-7]>0)and(fe[i-7]!=2):
bauernweissschlag.append(i)
bauernweissschlag.append(i-7)
if (fe[i-5]>0)and(fe[i-5]!=2):
bauernweissschlag.append(i)
bauernweissschlag.append(i-5)

#turmpositonweiss
turmpositionweiss=[]#Turmzuege
turmw=-4;x=0
for i in fe:
if i==turmw:
turmpositionweiss.append(x)
x=x+1

su=0 # turmanzahl bestimmen


for turmanzahl in turmpositionweiss:
su=su+1

turmzugew=[];turmschlagw=[]
k=0;ad=0 # dazuzaehlen fuer turmposition
for n in turmpositionweiss:
for v in range(1,5): #fuer die Richtungen 4x
if v==1:
ad=6 #ad fuer nach unten
if v==2:
ad=-6 #ad fuer nach oben
if v==3:
ad=1 #ad fuer nach rechts
if v==4:
ad=-1
#nach unten suchen
z=0;abbruchwert=0
for i in range(1,5): # ab turmposition schleife z.bsp 4x
z=z+ad
if fe[turmpositionweiss[0+k]+z]!=0:
break
else:
turmzugew.append(n) #von
turmzugew.append(turmpositionweiss[0+k]+z) #bis
abbruchwert=z
#Restglied dazu wenn ueber null=feind
if fe[turmpositionweiss[0+k]+abbruchwert+ad]>0:
if fe[turmpositionweiss[0+k]+abbruchwert+ad]!=2:
turmschlagw.append(n)
turmschlagw.append(turmpositionweiss[0+k]+abbruchwert+ad)
# wenn 2 tuerme k anders weil zweiter turm
if su==2:
k=1

#dampositonweiss
dampositionweiss=[]#Turmzuege
damw=-8;x=0
Programming a mini chess in phyton 32
for i in fe:
if i==damw:
dampositionweiss.append(x)
x=x+1

su=0 # damanzahl bestimmen


for damanzahl in dampositionweiss:
su=su+1

damzugew=[];damschlagw=[]
k=0;ad=0 # dazuzaehlen fuer turmposition
for n in dampositionweiss:
for v in range(1,5): #fuer die Richtungen 4x
if v==1:
ad=6 #ad fuer nach unten
if v==2:
ad=-6 #ad fuer nach oben
if v==3:
ad=1 #ad fuer nach rechts
if v==4:
ad=-1
#nach unten suchen
z=0;abbruchwert=0
for i in range(1,5): # ab damposition schleife z.bsp 4x
z=z+ad
if fe[dampositionweiss[0+k]+z]!=0:
break
else:
damzugew.append(n) #von
damzugew.append(dampositionweiss[0+k]+z) #bis
abbruchwert=z
#Restglied dazu wenn ueber null=feind
if fe[dampositionweiss[0+k]+abbruchwert+ad]>0:
if fe[dampositionweiss[0+k]+abbruchwert+ad]!=2:
damschlagw.append(n)
damschlagw.append(dampositionweiss[0+k]+abbruchwert+ad)
# wenn 2 damen k anders weil zweiter dam
if su==2:
k=1
#schraege weisse zuege
damzugews=[];damschlagws=[]
k=0;ad=0 # dazuzaehlen fuer damposition
for n in dampositionweiss:
for v in range(1,5): #fuer die Richtungen 4x
if v==1:
ad=7 #ad fuer nach unten
if v==2:
ad=-7 #ad fuer nach oben
if v==3:
ad=5 #ad fuer nach rechts
if v==4:
ad=-5
#nach unten suchen
z=0;abbruchwert=0
for i in range(1,5): # ab damposition schleife z.bsp 4x
z=z+ad
if fe[dampositionweiss[0+k]+z]!=0:
break
else:
damzugews.append(n) #von
damzugews.append(dampositionweiss[0+k]+z) #bis
abbruchwert=z
#Restglied dazu wenn ueber null=feind
if fe[dampositionweiss[0+k]+abbruchwert+ad]>0:
if fe[dampositionweiss[0+k]+abbruchwert+ad]!=2:
damschlagws.append(n)
damschlagws.append(dampositionweiss[0+k]+abbruchwert+ad)
# wenn 2 damen k anders weil zweiter dam
if su==2:
k=1

Programming a mini chess in phyton 33


damzuggerade=[];damzugschlagt=[]
damzuggerade.extend(damzugew)
damzuggerade.extend(damzugews)
damzugschlagt.extend(damschlagw)
damzugschlagt.extend(damschlagws)

kingpositionweiss=[]# kingposition
kingw=-9;x=0
for i in fe:
if i==kingw:
kingpositionweiss.append(x)
x=x+1
#berechne geradenzug fuer jede kingposition
kingzugweiss=[];kingweisss=[] #kingzuege
for i in kingpositionweiss:
if (fe[i+6]==0)and(fe[i+6]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i+6)
if (fe[i-6]==0)and(fe[i-6]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i-6)
if (fe[i+1]==0)and(fe[i+1]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i+1)
if (fe[i-1]==0)and(fe[i-1]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i-1)
if (fe[i+7]==0)and(fe[i+7]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i+7)
if (fe[i-7]==0)and(fe[i-7]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i-7)
if (fe[i+5]==0)and(fe[i+5]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i+5)
if (fe[i-5]==0)and(fe[i-5]!=2):
kingzugweiss.append(i)
kingzugweiss.append(i-5)
if (fe[i+6]>0)and(fe[i+6]!=2):
kingweisss.append(i)
kingweisss.append(i+6)
if (fe[i-6]>0)and(fe[i-6]!=2):
kingweisss.append(i)
kingweisss.append(i-6)
if (fe[i+1]>0)and(fe[i+1]!=2):
kingweisss.append(i)
kingweisss.append(i+1)
if (fe[i-1]>0)and(fe[i-1]!=2):
kingweisss.append(i)
kingweisss.append(i-1)
if (fe[i+7]>0)and(fe[i+7]!=2):
kingweisss.append(i)
kingweisss.append(i+7)
if (fe[i-7]>0)and(fe[i-7]!=2):
kingweisss.append(i)
kingweisss.append(i-7)
if (fe[i+5]>0)and(fe[i+5]!=2):
kingweisss.append(i)
kingweisss.append(i+5)
if (fe[i-5]>0)and(fe[i-5]!=2):
kingweisss.append(i)
kingweisss.append(i-5)

gesamtweiss=[]
weisszug=[] #alle weissen sammeln
weisszug.extend(bauernzugweiss)
weisszug.extend(turmzugew)
weisszug.extend(damzuggerade)
weisszug.extend(kingzugweiss)
weissschlag=[]
Programming a mini chess in phyton 34
weissschlag.extend(bauernweissschlag)
weissschlag.extend(turmschlagw)
weissschlag.extend(damzugschlagt)
weissschlag.extend(kingweisss)
gesamtweiss.extend(weisszug)
gesamtweiss.extend(weissschlag)

#fahre weiss
x=0;y=0
y=len(gesamtweiss)/2
weissreaktion=[]
for i in range(1,y+1): #fuehre alle weissen zuege aus

x=x+1
v=x-1;b=x
#print gesamtweiss[v],gesamtweiss[b]
weissreaktion.append(gesamtweiss[v])
weissreaktion.append(gesamtweiss[b])
x=x+1
ausweiss.append(weissreaktion)#zu ausweiss dazu
#return fe[7:11],fe[13:17],fe[19:23],fe[25:29],fe[31:35],weissreaktion
return weissreaktion
#****************************funktion ende***************************

#print gesamtschwarz
schwarzein=[]
x=0;y=0
y=len(gesamtschwarz)/2

for i in range(1,y+1): #fuehre alle schwarzen zuege aus rufe weisse reaktion
fe=f[:]
x=x+1
v=x-1;b=x
#print gesamtschwarz[v],gesamtschwarz[b]
schwarzein.append(gesamtschwarz[v])
schwarzein.append(gesamtschwarz[b])
fe[gesamtschwarz[b]]=fe[gesamtschwarz[v]]#ausfuehern
fe[gesamtschwarz[v]]=0
weiss() #weisse funktion aufrufen
x=x+1

#print "first"
#print f[7:11]
#print f[13:17]
#print f[19:23]
#print f[25:29]
#print f[31:35]
#print'+++++++++++++'

#print schwarzein #alle von bis schwarz


#print ausweiss #alle antworten
#antwort auf ersten von bis
#weiter berechne die Punkte auf brett
#fahre auf feld schwarzein--fahre ausweiss und punkte fuer varianten

x=0;y=0
y=len(gesamtschwarz)/2
za=0;zui=[];ges=[]
for i in range(1,y+1):
fa=f[:]
x=x+1
v=x-1;b=x
#print gesamtschwarz[v],gesamtschwarz[b]

ges.append(gesamtschwarz[v])
ges.append(gesamtschwarz[b])
fa[gesamtschwarz[b]]=fa[gesamtschwarz[v]]#ausfuehern
fa[gesamtschwarz[v]]=0
#hier innere addition
Programming a mini chess in phyton 35
add=0;zu=[]

zui.append(zu)
for k in range(7,11): #innere addition
if fa[k]>0:
add=add+fa[k]
if za==za:
x1=0;y1=0;v1=0;b1=0
y1=len(ausweiss[za])/2

for c in range(1,y1+1):
fi=fa[:]
x1=x1+1 #ueber antwort iterieren
v1=x1-1;b1=x1 # noch addition einf?gen
#print ausweiss[za][v1],ausweiss[za][b1]
fi[ausweiss[za][b1]]=fi[ausweiss[za][v1]]#ausfuehern
fi[ausweiss[za][v1]]=0
sus=0;suw=0#addiere innere summe
for k in range(7,11):
if fi[k]>0:
sus=sus+fi[k]
if fi[k]<0:
suw=suw+fi[k]
for k in range(13,17):
if fi[k]>0:
sus=sus+fi[k]
if fi[k]<0:
suw=suw+fi[k]
for k in range(19,23):
if fi[k]>0:
sus=sus+fi[k]
if fi[k]<0:
suw=suw+fi[k]
for k in range(25,29):
if fi[k]>0:
sus=sus+fi[k]
if fi[k]<0:
suw=suw+fi[k]
for k in range(31,35):
if fi[k]>0:
sus=sus+fi[k]
if fi[k]<0:
suw=suw+fi[k]

#print'sum',sus,abs(suw)
ab=abs(suw)-sus # unterschied berechnen
if sus<abs(suw):
zu.append(ab)
#zu.append(sus)
#zu.append(abs(suw))
x1=x1+1
#print'***************'
#print fi[7:11]
#print fi[13:17]
#print fi[19:23]
#print fi[25:29]
#print fi[31:35]
#print '****************'

#ergebnis von gesamtschwarz


#print'+++++++++++++'
#print fa[7:11]
#print fa[13:17]
#print fa[19:23]
#print fa[25:29]
#print fa[31:35]
#print'+++++++++++++++++++++++++++++++++++++++++++++++++++++'
x=x+1
za=za+1
#print "gesamtzuege"

#print "Zug=",ges
#print "unterschiede der materialien bei zug"
#print "Dif=",zui
Programming a mini chess in phyton 36
ne=[] # hier alle geringen unterschiede sammeln
for i in zui:
if i==[]:
ne.append([])
if i!=[]:
ne.append(max(i))

#print "maximalwerte aus unterschied"


#print "MiD=",ne

st=0;mi=[]
for k in ne:
st=st+1

if k==[]:
mi.append(st-1)
break

mii=[];mind=0 # wenn nicht [] und mindestestzahl


if ne==[]:
break
mind=min(ne)

# print mi #stelle von mi


# stelle ermitteln wo mind liegt
zam=0;zas=[]
for i in ne:
zam=zam+1
if ne==[]:
break
if i==mind:
zas.append(zam-1)
break
#print zas #stelle zas
zamzi=[]
zamzi.extend(mi)
zamzi.extend(zas)
#print "nimm erstes von"
#print zamzi

#print "zug nr waehlen:"


#print zamzi[0]
# aus ges wahl zamzi
n=0;n1=0
#print "Computer zieht von-bis:",ges[n],"-",ges[n1]
n=zamzi[0]*2
n1=n+1
print "Computer von:",ges[n],"-",ges[n1]

f[ges[n1]]=f[ges[n]]#ausfuehern
f[ges[n]]=0
#print'**************'
#print f[7:11]
#print f[13:17]
#print f[19:23]
#print f[25:29]
#print f[31:35]
#print'**************'
#damverwandlung
if f[31]==1:
f[31]=8
if f[32]==1:
f[32]=8
if f[33]==1:
f[33]=8
if f[34]==1:
f[34]=8

#spielstand
aus=0;auw=0#addiere innere summe
for k in range(7,11):
if f[k]>0:
Programming a mini chess in phyton 37
aus=aus+f[k]

if f[k]<0:
auw=auw+f[k]
for k in range(13,17):
if f[k]>0:
aus=aus+f[k]
if f[k]<0:
auw=auw+f[k]
for k in range(19,23):
if f[k]>0:
aus=aus+f[k]
if f[k]<0:
auw=auw+f[k]
for k in range(25,29):
if f[k]>0:
aus=aus+f[k]
if f[k]<0:
auw=auw+f[k]
for k in range(31,35):
if f[k]>0:
aus=aus+f[k]
if f[k]<0:
auw=auw+f[k]

q=[]
for i in f:
if i==3:
q.append('L')
if i==5:
q.append('S')
if i==4:
q.append('T')
if i==8:
q.append('D')
if i==9:
q.append('K')
if i==1:
q.append('+')
if i==0:
q.append('.')
if i==-3:
q.append('l')
if i==-5:
q.append('s')
if i==-4:
q.append('t')
if i==-8:
q.append('d')
if i==-9:
q.append('k')
if i==-1:
q.append('*')

print'***********',' ''***************'
print'*',q[0],q[1],q[2],q[3],'*',' *'' 7 8 9 10 *'
print'*', q[4],q[5],q[6],q[7],'*',' *'' 13 14 15 16 *'
print'*', q[8],q[9],q[10],q[11],'*',' *'' 19 20 21 22 *'
print'*', q[12],q[13],q[14],q[15],'*',' *'' 25 26 27 28 *'
print'*', q[16],q[17],q[18],q[19],'*',' *'' 31 32 33 34 *'

q=[]

print'***********',' ''***************'
print "Spielstand:","Computer:",aus,"p","Mensch:",abs(auw),"p"
if aus>abs(auw):
xxx=random.randint(1,6)
if xxx==1:
print"juhuhu ich bin besser,hab mehr Punkte"
if xxx==2:
print"ich bin super!!!"
if xxx==3:
print"bin ich nicht gut???"
Programming a mini chess in phyton 38
if xxx==4:
print"das ist mein bester Zug"
if xxx==5:
print"ich mach Dich platt"
if xxx==6:
print"Bald bist Du fertig"

if aus<abs(auw):
yyy=random.randint(1,6)
if yyy==1:
print"jau!!!das hab ich nicht gesehen!!"
if yyy==2:
print"warum muss das mir passieren?"
if yyy==3:
print"das tut weh!!!"
if yyy==4:
print"schade...wo ich schon so gut war"
if yyy==5:
print"ach nein!!!ohweh....!!!"
if yyy==6:
print"das ist nicht so schlimm.."
if aus==abs(auw):
zzz=random.randint(1,10)
if zzz==1:
print"es steht anscheinend ausgeglichen...mein Sieg ist nahe"
if zzz==2:
print"irgendwie sieht diese Stellung komisch aus"
if zzz==3:
print"das sieht schon gut aus!!!"
if zzz==4:
print"der Weg zum Sieg ist nahe"
if zzz==5:
print"das war ein guter Zug"
if zzz==6:
print"irgendwie bin ich doch gut"
if zzz==7:
print"das sieht nach 'Unentschieden'aus"
if zzz==8:
print"ok ich denke noch..."
if zzz==9:
print"mir ist nicht so gut"
if zzz==10:
print"willst Du das wirklich?"

if aus-abs(auw)==1:
aaa=random.randint(1,4)
if aaa==1:
print"hihi...ich habe Deinen Bauern geschlagen"
if aaa==2:
print"trara...dieses war der erste Streich"
if aaa==3:
print"hehe...schon bin ich im Vorteil!"
if aaa==4:
print"den nehme ich mir!"

if aus-abs(auw)==4:
bbb=random.randint(1,3)
if bbb==1:
print"haha->dein Turm ist mein"
if bbb==2:
print"steil..nun hab ich deinen Turm erobert!"
if bbb==3:
print"meck,meck,meck...dein Turm ist weg!!!"
if aus-abs(auw)==8:
ccc=random.randint(1,3)
if ccc==1:
print"super!!super!!->jetzt habe ich Deine Dame doch erwischt"
if ccc==2:
print"toll,toll,auch deine Dame ist nun weg!!"
if ccc==3:
print"dumm gelaufen...ich habe gewonnen"
if aus-abs(auw)==2:
Programming a mini chess in phyton 39
ddd=random.randint(1,3)

if ddd==1:
print"tralala...ich bin zwei Bauerneinheiten vorne"
if ddd==2:
print"zwo,zwo,zwo...da bin ich froh"
if ddd==3:
print"zwei Punkte vorn....ich bin enorm stark!"

if aus-abs(auw)==3:
eee=random.randint(1,3)
if eee==1:
print"gewaltig...ich bin drei Bauerneinheiten vor Dir!"
if eee==2:
print"eklatant ich bin so gut...."
if eee==3:
print"dieser Zug ist Dein Ende"

if aus-abs(auw)==5:
fff=random.randint(1,3)
if fff==1:
print"bin bestens drauf!-->Turm+Bauer habe ich erobert!"
if fff==2:
print"und dieses war der zweite Streich-Turm+Bauer vorne!!"
if fff==3:
print"das war ein schlechter Zug von Dir"

if aus-abs(auw)==6:
ggg=random.randint(1,3)
if ggg==1:
print"ich bin so gut!-->Turm+2xBauer habe ich schon erobert!"
if ggg==2:
print"ich werde immer besser!-->dein Turm+Bauer+Bauer ist weg!!"
if ggg==3:
print"aufgeben bitte!!!"
if aus-abs(auw)==9:
hhh=random.randint(1,3)
if hhh==1:
print"genial-->aufgeben bitte!eine Dame+1xBauer habe ich schon erobert!"
if hhh==2:
print"willst Du wirklich weiterspielen..."
if hhh==3:
print"ich mach Dich fertig !!!"
if aus-abs(auw)==10:
iii=random.randint(1,3)
if iii==1:
print"sauber-->wieder was erwischt,es sieht schlecht aus"
if iii==2:
print"dieser Zug vernichtet Dich !!!"
if iii==3:
print"Patzer,Patzer!!!"

if aus-abs(auw)==-1:
jjj=random.randint(1,3)
if jjj==1:
print"naja...bin einen Bauer hinten,das war Zufall!"
if jjj==2:
print"das macht gar nichts ich bin super!!!"
if jjj==3:
print"bald habe ich den Sieg errungen..."

if aus-abs(auw)==-2:
kkk=random.randint(1,3)
if kkk==1:
print"nunja...hab halt zwei Bauern weniger,denken!denken!"
if kkk==2:
print"das war fies von Dir"
if kkk==3:
print"jetzt kommt mein Angriff"
if aus-abs(auw)==-4:
lll=random.randint(1,3)
if lll==1:
print"auweh!wo ist mein Turm?"
if lll==2:
print"auch ohne Turm bin ich besser!!!"
Programming a mini chess in phyton 40
if lll==3:
print"Fehlzug von Dir!!!-->jetzt nehme ich Deine Dame!!"

if aus-abs(auw)==-8:
mmm=random.randint(1,3)
if mmm==1:
print"ach nein!!! meine Dame ist schon weg!"
if mmm==2:
print"egal...ich mach mir eine neue Dame!!"
if mmm==3:
print"mein Dame weg??-->nun werde ich Dich vernichten!!!"
if aus-abs(auw)==-9:
nnn=random.randint(1,3)
if nnn==1:
print"gibt es das?meine Dame?mein Bauer?"
if nnn==2:
print"auch ohne Dame+Bauer bin ich besser!!"
if nnn==3:
print"das war purer Zufall...ich bin gut"
if aus-abs(auw)==-3:
ooo=random.randint(1,3)
if ooo==1:
print"jetzt muss ich denken...hab halt drei Bauern weniger"
if ooo==2:
print"Achtung dein Turm!!!"
if ooo==3:
print"ich bin anscheinend im Vorteil"
if aus-abs(auw)==-5:
ppp=random.randint(1,3)
if ppp==1:
print"ouweh!wo ist mein Turm?wo ist mein Bauer?"
if ppp==2:
print"warum?...fehlt mir ein Turm???"
if ppp==3:
print"das ist unfair!!!"
if aus-abs(auw)==-10:
qqq=random.randint(1,3)
if qqq==1:
print"bist Du ein Schachcomputer?"
if qqq==2:
print"dieser Zug macht keinen Sinn...ich bin immmer noch besser!!"
if qqq==3:
print"Sieg,Sieg!!ich mach mir zwei Damen..10 Punkte weniger ist egal!"

Programming a mini chess in phyton 41


27. Appendix time and sky
The wonderful world
Now we dare to look into space. We travel to the end of our solar system. Our journey continues past
galaxies into worlds unknown to us. We are entering a world that
no one has seen it yet. Outside of space and time there is a wonderful place where there is no night. We
are entering a land with everlasting daylight. The land is flooded with light like clear crystal. Immeasu-
rable beauty is presented to our eyes. The streets there are made of pure gold and flooded with light as
if made of transparent glass. Pearls and precious stones are the building material. All known laws of
physics no longer exist. There is no passing time there, no worry, no suffering, no disease, no death.
Eternal peace, eternal joy, eternal friendship and indescribable happiness await us.
There are no more problems and pain. Dear reader, there is such a wonderful one
Place? If so, how can you get there?

I could spend hours in the starry sky at night


deepen, because to me this infinity of distant flaming worlds is like a bond between this and
future existence appears.
Wilhelm Freiherr von Humboldt
(1767-1835)

An oversized place
Who still knows August Hermann Francke today?

His work, the “Francke Foundations in Halle”, is still present. He lived from 1663 to 1727. Al-
ready at the age of 24 he realized that neither work nor profession, as well as the pursuit of
money, are the fulfillment of life.

Since a human life is immeasurably short, a hyphen between two years, he devotes all his
energy to fighting poverty. He founds orphanages and schools and provides training places for
young people.

But where is August Hermann Francke now? Does he live on in higher dimensions? Is there a
place called "Heaven" or "Paradise"?

This question moves the author.

Programming a mini chess in phyton 42


A livelihood
That was his creed and basis of his life [heavily abbreviated]:
„I recognize myself for a poor and wretched worm, who with his hereditary and real ones
Sins of God's wrath and injustice, temporal death and eternal damnation.
But the Son of God, Jesus Christ, gave himself for me and through his blood
reconciled with his father, so that God does not count my sins against me, but counts me in righteous-
ness, that I believe in the name of his only begotten Son. "
By such belief I am truly justified. In such justification of mine I have found peace with God, I am a
child of God, cheerfully comfort myself in his grace and know for sure that I will neither see nor taste
death, but that I have eternal life, and from death to life I am penetrated.
Nobody can add a cubit to its length, whether or not they worry about it. But God's way is different.
Because he does nothing that which is something, so that he himself may become all in all.
And all of this is constituted in the one; whoever believes in the Son has eternal life. Lord Jesus, your
good spirit guide me on a level path.
August Hermann Francke “1699

This livelihood from 1699 is still relevant today, it may seem old-fashioned
appear, but the author of these lines can heartily endorse this confession.
Now the author knows for sure, like August Hermann Francke once, that he will live on after death.
Why?

A gift
Eternal life as a gift:
The creed of August Hermann Francke can be asked very personally word for word, claim and
simply "believe". This invitation from God is addressed to “volunteers”, it is a gift.

August Hermann Francke

Where will you be a valued reader 150 years from now?

Programming a mini chess in phyton 43


Dimension of horror
The black hole

Our journey continues into immeasurable depths beyond space and time. Already from a distance
we hear the terrible cries of the unfortunate people who have to live in this horrible place. A yawning
black hole opens before our eyes. We must be careful not to get too close to this hole so that we are not
torn apart. Warns them, warns them the voices call out, we must be here forever separated from our lo-
ved ones, we must suffer eternal darkness, pain and horror. Lost, we are lost, we must be here forever.

I do want to, but I cannot do what is good. Because I don't do the good that I want; but the evil that I
don't want, that's what I do. But if I do what I do not want, it is not I who do it, but the sin that dwells
in me. That is what we need to think about, everybody explore his heart. I miserable man! Who will de-
liver me from the dead body?

There is hope
We leave this place in a hurry and sad. We don't want to stay here a minute longer.
With the utmost effort we manage to escape. Then it occurs to me: No one should be lost and come to
this terrible place.

Did not the good, merciful, holy and just triune God, who loves us always, send his Son so that we may
not perish. Jesus obtained redemption for our sins through his vicarious death on the cross.

When we confess our sins, He is faithful and righteous to forgive our sins and cleanse
us from all injustice. (The Bible: 1 John 1: 9)

For God so loved the world that he gave his only begotten Son, so that everyone who
believes in him should not perish, but have eternal life.
(The Bible: John 3:16)

I am the resurrection and the life; whoever believes in me will live even if he dies "(The
Bible: John 11:25)

For if you confess with your mouth that Jesus is the Lord and believe in your heart
that God raised him from the dead, you will be saved. (The Bible: Romans 10.9)

Programming a mini chess in phyton 44


28. The valuable time

Time is very valuable.

Where will we be after death? "At home with the Lord in heaven" or lost forever.

I have learned two important things in my life: that I am a great sinner and that
Christ is an even greater Savior.
[Sir Isaac Newton 1643-1727]

*Soli Deo gloria*

Programming a mini chess in phyton 45


29.imprint

mpressum, copyright, care and errors. Great care was taken in compiling the text and the images.

However, errors cannot be completely ruled out. The publisher and the author cannot accept any legal
responsibility or liability for incorrect information and their consequences. All rights reserved, inclu-
ding photomechanical reproduction and storage in electronic media. Commercial use of the models
and works shown in this book is only permitted with the consent of the © author. For hardware and
software names and other keywords that are protected as registered trademarks, it was not possible in
all cases to determine promptly whether a trademark protection exists , for this reason the ®R symbol
is not used in this book. Edition No. 1- 2020 / self-published.

The author:

Gerald Arnold Wartensteiner

Programming a mini chess in phyton 46

You might also like