[ create a new paste ] login | about

Link: http://codepad.org/xPlrDZ9n    [ raw code | output | fork ]

C++, pasted on Dec 28:
// odai6_111chess.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"

class List
{
protected:
	int pos = 0;
	int max = 0;
	int first = 0;
	int data[100];
public:
	List();
	int begin();
	int next();
	int erase();
	void add(int);
	int size();
};
List::List(){}
int List::begin(){
	int pos = 0;
	if (max > 0)
		return data[first];
	else
		return -1;
}
int List::next(){
	int i;
	if (pos + 1 == 100)
		pos = -1;
	if (pos + 1 > max)
		return -1;
	pos++;
	i = pos + first;
	if (i >= 100)
		i -= 100;
	return data[i];
}
int List::erase(){
	if (max <= 0)
		return -1;
	max--;
	first++;
	return 0;
}
void List::add(int value){
	int i = max + first;
	if (i >= 100)
		i -= 100;
	data[i] = value;
	max++;
}
int List::size(){
	return max;
}

int data[] = {-17, -15, -6, 10, 15, 17, 6, -10};
int data2[][2] = { { -1, -2 }, { 1, -2 }, { 2, -1 }, { 2, 1 }, { -1, 2 }, { 1, 2 }, { -2, 1 }, { -2, -1 } };
int brd[64];
void setbrd(){
	for (int i = 0; i < 64; i++)
		brd[i] = 99;
}
void search(int pos, int nest){
	int newpos, *dat = data;
	int posx = pos % 8, posy = pos / 8, newx, newy, *px = &(data2[0][0]), *py = &(data2[0][1]);
	List list;
	for (int i = 0; i < 8; i++){
		newpos = pos + *(dat++);
		newx = posx + *px;
		newy = posy + *py;
		px += 2; py += 2;
		if (newpos < 0 || newpos >= 64 || newx < 0 || newx >= 8 || newy < 0 || newy >= 8)
			continue;
		if (brd[newpos] > nest){
			list.add(newpos);
			brd[newpos] = nest;
		}
	}
	while (list.size() > 0){
		newpos = list.begin();
		search(newpos, nest + 1);
		list.erase();
	}

}
void disp(){
	int *p = brd;
	while (p < brd + 64){
		for (int i = 0; i < 8; i++){
			_tprintf(_T("%3d"), *(p++));
		}
		_tprintf(_T("\n"));
	}
}
int _tmain(int argc, _TCHAR* argv[])
{
	setbrd();
	brd[0] = 0;
	search(0, 1);
	disp();
	return 0;
}


Output:
1
2
Line 9: error: ISO C++ forbids initialization of member 'pos'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: