-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
96 lines (87 loc) · 2.78 KB
/
App.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React, { Component } from "react";
import UserSettings from "./components/UserSettings";
import { calcRooks } from "./RooksEquation";
import { calcQueens } from "./QueensEquation";
import Board from "./components/Board";
import "./App.css";
class App extends Component {
constructor(props) {
super(props);
this.state = {
tileColor: ["rgba(0, 0, 0, 0.7)", "rgba(255, 255, 255, 0.7)"],
allRes: null,
solutionNumber: 0,
displaySolution: null,
totalNumberOfSolutions: null,
boardDim: 0,
gameType: "Rooks"
};
}
findSolutions = async n => {
if (this.state.gameType === "Rooks") {
await this.setState({ allRes: calcRooks(Number(n)) });
} else {
await this.setState({ allRes: calcQueens(Number(n)) });
}
await this.setState({ displaySolution: this.state.allRes[0] });
this.setState({ totalNumberOfSolutions: this.state.allRes.length });
};
theRook(local, displaySolution, GameType) {
if (displaySolution) {
return displaySolution.map((possi, possj) => {
if ("poss" + possj + possi === local) {
if (GameType === "Rooks") {
return <img src={require("./rook.svg")} className="Rook" />;
} else {
return <img src={require("./queen.svg")} className="Rook" />;
}
}
});
}
}
colorChoice = (color1, color2) => {
this.setState({ tileColor: [color1, color2] });
};
updateSolutionNumber = value => {
this.setState({ solutionNumber: value });
this.setState((prevState, props) => {
return { displaySolution: prevState.allRes[value] };
});
};
updateBoardDim = settingsBoardDim => {
this.setState({ boardDim: settingsBoardDim });
};
updateGameType = type => {
this.setState({ gameType: type });
};
////////////////////////////////////////////
solutionDisplayUpdate() {}
render() {
return (
<div className="MaxWidth">
<h1> nQueens & nRooks Algorithm </h1>
<div className="CenteringContainer">
<div className="BoardPositions">
<Board
tileColor={this.state.tileColor}
pieceType={this.state.gameType}
boardDim={this.state.boardDim}
displaySolution={this.state.displaySolution}
theRook={this.theRook}
theChosenTileColor={this.state.tileColor}
/>
</div>
<UserSettings
gameType={this.updateGameType}
updateBoardDim={this.updateBoardDim}
findSolutions={this.findSolutions}
colorChoice={this.colorChoice}
totalNumberOfSolutions={this.state.totalNumberOfSolutions}
updateSolutionNumber={this.updateSolutionNumber}
/>
</div>
</div>
);
}
}
export default App;