<commit_before>/*
 * BitboardCA. Cellular Automata using bitboard algorithms.
 * Copyright (C) <NAME> <<EMAIL>> http://wasabi.in/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */



#include "bbca.h"

#include <cstdlib>
#include <ctime>

using namespace BitboardCA;

CA::CA(int size_x, int size_y)
{
	this->size_x = size_x;
	this->size_y = size_y;
	this->board_size_x = (size_x-1)/8+3;
	this->board_size_y = (size_y-1)/8+3;
	boards.resize(board_size_x * board_size_y, 0ULL);
}

CA::~CA()
{
}

void CA::step()
{
	static std::vector<Bitboard> boards2(boards.size());

	// calc outer totalistic each bitboards
	for(int y=1; y<board_size_y-1; y++)
		for(int x=1; x<board_size_x-1; x++)
		{
			boards2[x+y*board_size_x] = stepByOuterTotalistic(
					boards[(x  )+(y  )*board_size_x],
					boards[(x-1)+(y-1)*board_size_x], boards[(x  )+(y-1)*board_size_x], boards[(x+1)+(y-1)*board_size_x],
					boards[(x-1)+(y  )*board_size_x],                                   boards[(x+1)+(y  )*board_size_x],
					boards[(x-1)+(y+1)*board_size_x], boards[(x  )+(y+1)*board_size_x], boards[(x+1)+(y+1)*board_size_x]
			);
		}

	// mask for usable a expect multiple of 8
	// mask X
	static Bitboard mask_x[8] = {
		0xffffffffffffffffULL,
		0x8080808080808080ULL,
		0xc0c0c0c0c0c0c0c0ULL,
		0xe0e0e0e0e0e0e0e0ULL,
		0xf0f0f0f0f0f0f0f0ULL,
		0xf8f8f8f8f8f8f8f8ULL,
		0xfcfcfcfcfcfcfcfcULL,
		0xfefefefefefefefeULL
	};<commit_msg>fixed crash on testGlider and some testcases.<commit_after>/*
 * BitboardCA. Cellular Automata using bitboard algorithms.
 * Copyright (C) <NAME> <<EMAIL>> http://wasabi.in/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */



#include "bbca.h"

#include <cstdlib>
#include <ctime>

using namespace BitboardCA;

CA::CA(int size_x, int size_y)
{
	this->size_x = size_x;
	this->size_y = size_y;
	this->board_size_x = (size_x-1)/8+3;
	this->board_size_y = (size_y-1)/8+3;
	boards.resize(board_size_x * board_size_y, 0ULL);
}

CA::~CA()
{
}

void CA::step()
{
	std::vector<Bitboard> boards2(boards.size());

	// calc outer totalistic each bitboards
	for(int y=1; y<board_size_y-1; y++)
		for(int x=1; x<board_size_x-1; x++)
		{
			boards2[x+y*board_size_x] = stepByOuterTotalistic(
					boards[(x  )+(y  )*board_size_x],
					boards[(x-1)+(y-1)*board_size_x], boards[(x  )+(y-1)*board_size_x], boards[(x+1)+(y-1)*board_size_x],
					boards[(x-1)+(y  )*board_size_x],                                   boards[(x+1)+(y  )*board_size_x],
					boards[(x-1)+(y+1)*board_size_x], boards[(x  )+(y+1)*board_size_x], boards[(x+1)+(y+1)*board_size_x]
			);
		}

	// mask for usable a expect multiple of 8
	// mask X
	static Bitboard mask_x[8] = {
		0xffffffffffffffffULL,
		0x8080808080808080ULL,
		0xc0c0c0c0c0c0c0c0ULL,
		0xe0e0e0e0e0e0e0e0ULL,
		0xf0f0f0f0f0f0f0f0ULL,
		0xf8f8f8f8f8f8f8f8ULL,
		0xfcfcfcfcfcfcfcfcULL,
		0xfefefefefefefefeULL
	};
{'fraction_non_alphanumeric': 0.1294398092967819, 'fraction_numerical': 0.0467222884386174, 'mean_word_length': 4.00119189511323, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6665231', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1564, 'n_words': 417}