-
Notifications
You must be signed in to change notification settings - Fork 1
/
knight_moves.cpp
executable file
·82 lines (63 loc) · 1.36 KB
/
knight_moves.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
* File Name : knight_moves.cpp
* Purpose :
* Creation Date : 12-04-2011
* Last Modified : Tuesday 19 July 2011 04:37:37 PM IST
* Created By : Nitin
_._._._._._._._._._._._._._._._._._._._._.*/
#include <iostream>
#include <cstdlib>
#define DEBUG 1
#define fori(i,j,k) for(int i = j; i < k; i++)
/*
* Hypothetical function which will return the
* number of possible knight moves from a given (x,y)
* cordinate on chess.
*/
int num_moves(){
int _temp = rand()%8;
return _temp;
}
int main(){
int num;
std::cout << "No of moves: ";
std::cin >> num ;
if(DEBUG) std::cout << "input is " << num << std::endl;
int arr[num];
int p_calc_moves[8][8];
/*
* Initialise 2-D array
*/
fori(j,0,8){
fori(k,0,8){
p_calc_moves[j][k] = -1;
}
}
/*
* print 2-D array
*/
fori(j,0,8){
fori(k,0,8){
std::cout << p_calc_moves[j][k] << " ";
}
std::cout << std::endl;
}
int c_x = 3, c_y = 3, _prob = 0;
fori(i,0,num){
if(p_calc_moves[c_x][c_y] == -1){ // prob for this pt is not calculated
_prob = num_moves();
p_calc_moves[c_x][c_y] = _prob;
}
else
_prob = p_calc_moves[c_x][c_y];
}
/*
* print 2-D array
*/
fori(j,0,8){
fori(k,0,8){
std::cout << p_calc_moves[j][k] << " ";
}
std::cout << std::endl;
}
}