Movement of Knight in Chess!

Hi everyone,
So in chess, the knight moves in a very special way:
either: two squares forward and one to the side
or : one square forward and two to the side
Now I need to write a program to describe
the Probability of the moves of the horse (using arrays).

I don't need you guys to do the assignment, as that would be
unprofessional of me, but I would like to know what are the steps
that I should use.

Thanks,
Abdul
Last edited on
I have no idea what you're asking. Probability of what?
Now I need to write a program to describe
the Probability of the moves of the horse (using arrays).

As written, that doesn't really make sense. In what context are you describing probability?
Did you mean possibility ?

BTW. Knights can move also backward.
The probability of the knight moving here or there would depend on the position of every other piece on the board. I remember reading somewhere that there are more possible board layouts by the fourth move in chess then there have been seconds since the universe was created. Assuming that is even remotely true, this isn't a very realistic assignment.

For example, if the knight moves on the player's first turn he can only go one of two ways since the board edges block five of his moves and a pawn blocks a sixth. There are twenty possible opening moves in chess and each knight accounts for two of them. So assuming random distribution, since only an idiot would open with his knight like this, there is a 5% chance of a knight landing on one of four possible spaces (someone check my math? IDK if I did that right :P). Now take a minute and try to imagine the second turn, if the knight didn't move: if neither the rook-pawn or the bishop-pawn moved up one space to block either of his moves, if the king-pawn or queen-pawn moved up and out of his way to free up that third option. If he did move on the previous turn and he moves again this turn, then each knight can land on any one of three squares each. Do you kind of see where this is going? It gets out of hand REALLY quickly.
Last edited on
It doesn't make sense to talk about the probability of a particular move of a chess piece because moves are not primarily decided by random processes.
I wrote this program a couple of years ago. Perhaps it helps. It calculates the number of paths from a certain starting square to any square on the board, assuming the knight only moves forwards. From these numbers you can perhaps calculate the probabilities you seek.

http://ideone.com/Hu2eZF

Sample output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1013  1449  2092  2186  2030  1937  1512  1148  

483   597   757   897   971   869   559   425   

168   256   384   382   336   332   279   209   

91    99    124   154   185   154   93    69    

27    44    75    64    54    55    55    39    

17    16    18    27    37    28    14    11    

3     9     14    12    6     10    11    8     

3     3     1     6     7     6     1     2     

0     2     3     2     0     2     2     2     

1     0     0     1     2     1     0     0     

0     0     1     0     0     0     1     0     

0     0     0     0     1     0     0     0     


13,367 paths from the starting position to the top row.


In this sample run, the knight is starting at the bottom row, first column.
The calculation is recursive. For example, the 7 comes from 3+2+1+1. The board is 8x12 in this sample run. The board size and starting position can be chosen to be any value, though the bigger the board the longer it will take to calculate.
Last edited on
The probability the assignment is talking about is that I should ask the user an input of two arrays in order to know the position of the knight, then the program should give the movement options of the knight.....which is L-shaped. so usually it should have 8 options.......however the chess table is limited with 8 rows and 8 columns, so if it is in the corner, it should have less options.

So what I am hoping for is an outline of what I should do.

Appreciated,
Abdul
Fill an array with all relative position of the knight. Add all those relative position to the absolute position of the knight. If that is out of the board it is an invalid draw.

That has really nothing to do with probability.
This is what I did, I just need tp use array to input the numbers, how?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;


void probability (int r, int c){
    
    cout<< "the probabilities are the following: " << endl;
    
    
    if (r + 2 <= 8 && c + 1 <= 8 )
    cout<< r + 2 <<"\t"<< c + 1 <<endl;
    if (r + 2 <= 8 && c - 1 <= 8 )
    cout<< r + 2 <<"\t"<< c - 1 <<endl;
    if (r - 2 <= 8 && c + 1 <= 8 )
    cout<< r - 2 <<"\t"<< c + 1 <<endl;
    if (r - 2 <= 8 && c - 1 <= 8 )
    cout<< r - 2 <<"\t"<< c - 1 <<endl;
    if (r + 1 <= 8 && c + 2 <= 8 )
    cout<< r + 1 <<"\t"<< c + 2 <<endl;
    if (r + 1 <= 8 && c - 2 <= 8 )
    cout<< r + 1 <<"\t"<< c - 2 <<endl;
    if (r - 1 <= 8 && c + 2 <= 8 )
    cout<< r - 1 <<"\t"<< c + 2 <<endl;
    if (r - 1 <= 8 && c - 2 <= 8 )
    cout<< r - 1 <<"\t"<< c - 2 <<endl;
}

int main()
{

   int r, c;
   
   cout<<"enter the raw: ";
   cin>>r;
   cout<<"enter the column: ";
   cin>>c;
   
   probability(r,c);
    return 0;
}
I don't think the assignment means two arrays, I think it means two dimensions. Might this be a translation error? For example, one dimension, 'A' is used to describe the latitude and another '2' is used to describe the longitude would give the kight a position of "A2" on the board. From there the rest of the assignment, describing the possible moves from the current position, makes more sense. Otherwise an array is just a consecutively stored stream of data, which doesn't make a whole lot of sense in the context of chess unless you're describing a series of moves.
Last edited on
Yes, apologies, I studied English long time ago in the US.... ☺
I didn't mean two arrays, but rather 2D (two dimensional) array.

Thanks,
Abdul
Topic archived. No new replies allowed.