Commit 7a981414 authored by hosein's avatar hosein

police -> move deleted

parent 7eb920d2
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Police.iml" filepath="$PROJECT_DIR$/Police.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
package mma;//package src;
import mma.PlayGround;
import mma.Police;
import mma.Thief;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Enter n: ");
int n = input.nextInt();
System.out.print("Enter m: ");
int m = input.nextInt();
System.out.print("Enter police numbers: ");
int pn = input.nextInt();
PlayGround playGround = new PlayGround(n, m, pn);
int[][] positions = playGround.putRandom();
Thief thief = new Thief(positions[pn][0], positions[pn][1]);
Police[] polices = new Police[pn];
for (n = 0; n < pn; n++)
polices[n] = new Police(positions[n][0], positions[n][1]);
//--------------------------------------------------------------------------------
do {
playGround.policeSeeThief();
} while(!playGround.catchThief());
}
}
package mma;
import java.util.Random;
public class PlayGround {
private int[][] ground, thiefsituation;
int n, m, policeNumbers;
PlayGround(int n, int m, int policeNumbers) {
this.n = n;
this.m = m;
this.policeNumbers = policeNumbers;
ground = new int[n][m];
thiefsituation = new int[1][1];
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
ground[i][j] = 0;
}
public void show() {
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (ground[i][j] == 0)
System.out.print("-");
else if (ground[i][j] == 1) // police
System.out.print("X");
else // Dozd
System.out.print("*");
}
System.out.println("");
}
}
public int[][] putRandom() {
int[][] positions = new int[policeNumbers + 1][2];
int i, j, k;
Random rand = new Random();
if (n * m < policeNumbers) System.out.println("Error!! NOT ENOUGH SPACE FOR POLICES AND THIEF IN GROUND");
else {
for (k = 0; k < policeNumbers; k++) { // police
i = rand.nextInt();
j = rand.nextInt();
if (ground[i][j] == 0) {
ground[i][j] = 1;
positions[k][0] = i; // x
positions[k][1] = j; // y
} else k--;
}
for (k = 0; k < 1; k++) { // thief
i = rand.nextInt();
j = rand.nextInt();
if (ground[i][j] == 0) {
ground[i][j] = 1;
positions[policeNumbers][0] = i; // x
positions[policeNumbers][1] = j; // y
thiefsituation[0][0] = i; // x
thiefsituation[0][1] = j; // y
}
}
}
return positions;
}
public void change(int[][] newPolicesSituation, int xThief, int yThief) {
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
ground[i][j] = 0;
for (i = 0; i < policeNumbers; i++)
ground[newPolicesSituation[i][0]][newPolicesSituation[i][1]] = 1;
ground[xThief][yThief] = -1;
}
public int[][] getGround() {
return ground;
}
public boolean policeSeeThief() {
int i, j, I, J;
if (thiefsituation[0][0] > 1) i = thiefsituation[0][0] - 2;
else i = 0;
if (thiefsituation[0][0] < n - 2) I = thiefsituation[0][0] + 3;
else I = n;
if (thiefsituation[0][1] > 1) j = thiefsituation[0][1] - 2;
else j = 0;
if (thiefsituation[0][1] < m - 2) J = thiefsituation[0][1] + 3;
else J = m;
for (; i < I; i++)
for (; j < J; j++)
if (ground[i][j] == -1)
return true;
return false;
}
public boolean catchThief() {
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (ground[i][j] == 100)
return true;
return false;
}
}
package mma;
import java.util.Random;
public class Police {
private int x, y;
private static boolean see;
Police(int x, int y) {
this.x = x;
this.y = y;
see = false;
}
public int[][] move(int n, int m) {
boolean i, j, I, J;
i = j = I = J = false;
if (x != 0) i = true;
if (x != n - 1) I = true;
if (y != 0) j = true;
if (y != m - 1) J = true;
Random random = new Random();
int[][] Return = new int[1][1];
while (true) {
switch (random.nextInt() % 8) {
case 0:
if (i == true && j == true) {
Return[0][0] = x - 1; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 1:
if (i == true) {
Return[0][0] = x - 1; // x
Return[0][1] = y; // y
return Return;
}
break;
case 2:
if (i == true && J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 3:
if (i == true) {
Return[0][0] = x; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 4:
if (J == true) {
Return[0][0] = x; // x
Return[0][1] = y + 1; // y
return Return;
}
break;
case 5:
if (i == true && J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y - 1; // y
return Return;
}
break;
case 6:
if (J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y; // y
return Return;
}
break;
case 7:
if (I == true && J == true) {
Return[0][0] = x + 1; // x
Return[0][1] = y + 1; // y
return Return;
}
}
}
}
public int[][] getSituation() {
int[][] Return = new int[1][1];
Return[0][0] = x;
Return[0][1] = y;
return Return;
}
}
\ No newline at end of file
public class Thief {
private int x, y;
private boolean see;
Thief(int x, int y) {
this.x = x;
this.y = y;
see = false;
}
}
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