{Array(3)
.fill(null)
.map((item1, i) => {
return (
{Array(3)
.fill(null)
.map((item2, j) => {
return this.renderSquare(3 * i + j);
})}
);
})}
);
}
}
//1
class Game extends React.Component {
constructor(props) {
super(props);
this.state = {
history: [
{
squares: Array(9).fill(null),
x: 0,
y: 0,
},
],
stepNumber: 0,
XIsNext: true,
change: true,
};
}
handleClick(i) {
const history = this.state.history.slice(0, this.state.stepNumber + 1);
const current = history[history.length - 1];
const squares = current.squares.slice();
// console.log(i,"i")
if (calculateWinner(squares).winner || squares[i]) {
return;
}
squares[i] = this.state.XIsNext ? "X" : "O";
this.setState({
history: history.concat([
{
squares: squares,
x: Math.floor(i / 3),
y: i % 3,
},
]),
stepNumber: history.length,
XIsNext: !this.state.XIsNext,
});
}
jumpTo(step) {
this.setState({
stepNumber: step,
XIsNext: step % 2 === 0,
});
}
changeDesc() {
this.setState({
change: !this.state.change,
});
console.log(this.state.change);
}
render() {
const history = this.state.history;
const current = history[this.state.stepNumber];
// const winner = calculateWinner(current.squares);
const result = calculateWinner(current.squares);
const winner = result.winner;
// console.log(winner,'winner')
const lines = result.winnerlines;
// console.log(lines,'1lines23')
const change = this.state.change;
var moves = history.map((step, move) => {
const desc = move ? "Go to move #" + move : "Go to game start";
const blod = this.state.stepNumber === move ? "blod" : "";
return (