Commit e19b199d authored by 9731301's avatar 9731301

add User class

parent 3c6038f1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/src" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="7be08370-19a4-4528-ab9b-d4cb0ec736c4" name="Default Changelist" comment="" /> <list default="true" id="7be08370-19a4-4528-ab9b-d4cb0ec736c4" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/User.java" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
...@@ -14,7 +18,11 @@ ...@@ -14,7 +18,11 @@
</list> </list>
</option> </option>
</component> </component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/src" />
</component>
<component name="ProjectId" id="1Zsmu4mM7KcQDh52oJP40I8FmWM" /> <component name="ProjectId" id="1Zsmu4mM7KcQDh52oJP40I8FmWM" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" /> <option name="showExcludedFiles" value="true" />
...@@ -22,9 +30,24 @@ ...@@ -22,9 +30,24 @@
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
</component> </component>
<component name="RunManager">
<configuration name="Othello" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Othello" />
<module name="MyOthello" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Othello" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration"> <component name="SvnConfiguration">
<configuration /> <configuration />
</component> </component>
...@@ -36,10 +59,56 @@ ...@@ -36,10 +59,56 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1585636394558</updated> <updated>1585636394558</updated>
<workItem from="1585636407800" duration="72000" /> <workItem from="1585636407800" duration="72000" />
<workItem from="1585656097487" duration="2378000" />
<workItem from="1585659438353" duration="9321000" />
<workItem from="1585687211713" duration="16102000" />
<workItem from="1585733466673" duration="521000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="WindowStateProjectService">
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser" timestamp="1585694421216">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1585694421216" />
<state width="1493" height="201" key="GridCell.Tab.0.bottom" timestamp="1585703421720">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="201" key="GridCell.Tab.0.center" timestamp="1585703421720">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="201" key="GridCell.Tab.0.left" timestamp="1585703421720">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="201" key="GridCell.Tab.0.right" timestamp="1585703421720">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1585703421720" />
<state width="1493" height="182" key="GridCell.Tab.1.bottom" timestamp="1585671521268">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="182" key="GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824" timestamp="1585671521268" />
<state width="1493" height="182" key="GridCell.Tab.1.center" timestamp="1585671521268">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="182" key="GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824" timestamp="1585671521268" />
<state width="1493" height="182" key="GridCell.Tab.1.left" timestamp="1585671521267">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="182" key="GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824" timestamp="1585671521267" />
<state width="1493" height="182" key="GridCell.Tab.1.right" timestamp="1585671521268">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="182" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1585671521268" />
<state x="813" y="283" key="com.intellij.ide.util.TipDialog" timestamp="1585733471645">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="813" y="283" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1585733471645" />
</component>
</project> </project>
\ No newline at end of file
...@@ -17,12 +17,12 @@ public class Block { ...@@ -17,12 +17,12 @@ public class Block {
this.color = color; this.color = color;
} }
public Character changeColor(){ public void changeColor(){
if (color.equals('b')){ if (color.equals('b')){
return 'w'; setColor('w');
} }
else else
return 'c'; setColor('b');
} }
public int getRow() { public int getRow() {
......
import java.util.ArrayList;
public class User {
private ArrayList<Block> userBlocks;
private ArrayList<Block> availableBlocksToPick;
private char color;
public User(){
userBlocks = new ArrayList<Block>();
availableBlocksToPick = new ArrayList<Block>();
}
public void addBlock(Block block){
userBlocks.add(block);
}
public boolean isAvailableBlockToPick(Block block , ArrayList<Block> blocks ) {
int i, j;
int flag1 = 0;
int flag2 = 0;
int flag3 = 0;// to know you can pick an empty block with help of checking changing color
if (!block.getColor().equals('n')) {
return false;
}
//check down
for (i = block.getRow(); i > 8; i++) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getRow() == block.getRow() + 1 && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getRow() == i && block1.getColumn() == block.getColumn() && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
//check up
flag1 = 0;
flag2 = 0;
for (i = block.getRow() - 1; i >= 0; i--) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getRow() == block.getRow() - 1 && block1.getColumn() == block.getColumn() && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getRow() == i && block1.getColumn() == block.getColumn() && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
//check right
flag1 = 0;
flag2 = 0;
for (i = block.getColumn() + 1; i < 8; i++) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getColumn() == block.getColumn() + 1 && block1.getRow() == block.getRow() && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getColumn() == i && block1.getRow() == block.getRow() && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
//check left
flag1 = 0;
flag2 = 0;
for (i = block.getColumn() - 1; i >= 0; i--) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getColumn() == block.getColumn() - 1 && block1.getRow() == block.getRow() && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getColumn() == i && block1.getRow() == block.getRow() && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
//check up and right
flag1 = 0;
flag2 = 0;
for (i = block.getColumn() + 1, j = block.getRow() - 1; i < 8 && j > -1; i++, j--) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getColumn() == block.getColumn() + 1 && block1.getRow() == block.getRow() + 1 && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getColumn() == i && block1.getRow() == j && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
//check down and left
flag1 = 0;
flag2 = 0;
for (i = block.getColumn() - 1, j = block.getRow() + 1; i > -1 && j < 8; i--, j++) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getColumn() == block.getColumn() - 1 && block1.getRow() == block.getRow() + 1 && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getColumn() == i && block1.getRow() == j && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
//check down and right
flag1 = 0;
flag2 = 0;
for (i = block.getColumn() + 1, j = block.getRow() + 1; i < 8 && j < 8; i++, j++) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getColumn() == block.getColumn() + 1 && block1.getRow() == block.getRow() - 1 && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getColumn() == i && block1.getRow() == j && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
//check up and left
flag1 = 0;
flag2 = 0;
for (i = block.getColumn() - 1, j = block.getRow() - 1; i < -1 && j < -1; i--, j--) {// find the next block with chosen block color
for (Block block1 : blocks) {
if (block1.getColumn() == block.getColumn() - 1 && block1.getRow() == block.getRow() - 1 && block1.getColor().equals(color)) {
flag1 = 1;
break;
}
if (flag2 == 1) {// to not change " w b b b w b b w " to "w w w w w w w w"
break;
}
if (!block1.getColor().equals('n') && block1.getColumn() == i && block1.getRow() == j && block1.getColor().equals(color)) {
flag2 = 1;
flag3 = 1;
}
}
if (flag1 == 1)
break;
}
if (flag3 == 0) {
return false;
}
return true;
}
/* public void updateAvailableBlockToPick(ArrayList<Block> blocks){
for (Block block : blocks){
if( isAvailableBlockToPick(block , blocks) == true){
availableBlocksToPick.add(block);
}
}
}*/
public void addAvailableBlockToPick(Block block){
availableBlocksToPick.add(block);
}
public void removeAvailableBlockToPick(Block block){
availableBlocksToPick.remove(block);
}
public char getColor() {
return color;
}
public void setColor(char color) {
this.color = color;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment