Write a program to play the game of SIM with eight points (labeled A-H). Again,
ID: 3598415 • Letter: W
Question
Write a program to play the game of SIM with eight points (labeled A-H). Again, the two players are RED and BLUE; you can assume that RED moves first by convention; each player alternately chooses an edge to "claim" for the given color; and the loser is the player who is forced to create a complete triangle of edges in their own color. Your program should play interactively against the user. It needn't involve any fancy graphics or interface, but it should play a decent and competitive game of SIM. The interaction could be entirely textual, and could look something like this: Are you playing Red? (Y/N): Y RED move: A, B BLUE move: E, G etc Some notes: you might want to use alpha-beta pruning (it'll come in handy for the next problem anyway). In any event, whatever algorithmic strategy you use for your program, you should explain and document your approach. Since the computer program will probably not display the current state of the game (though of course it could), you may want to play against the program with a paper-and-colored-pencil representation of the game board handy. You should submit the important source code for your program (i.e., the major procedures for deciding on a next move) and a sample game or two to show hovw it plays the gameExplanation / Answer
package com.one;
public class X00000000 extends Polynomial {
public static void main(String args[]) throws Exception {
Polynomial p = new X00000000(" X^5"), q = new X00000000("X^2 - X + 1");
Utility.run(p, q);
}
public X00000000(String s) {
// parse string character by character
double coef = 0; // coefficient of term
int deg = 0; // degree of term
String[] terms = s.split(" ");
for (int i = 0; i < terms.length; i++) {
String term = terms[i];
// System.out.println("term:"+term);
String prevTerm = "";
if (i != 0)
prevTerm = terms[i - 1];
if (term.startsWith("X")) {
if (term.length() == 3 && term.contains("^")) {
coef = 1;
deg = Integer.parseInt(term.substring(2));
} else if (term.length() == 1) {
deg = 1;
if (prevTerm.equals("-"))
coef = -1;
else
coef = 1;
}
} else if (term.startsWith("-") || term.startsWith("+"))
continue;
else if (term.length() == 1 && Character.isDigit(term.charAt(0))) {
coef = Integer.parseInt(term);
if (prevTerm.equals("-"))
coef *= -1;
deg = 0;
}
Term T = new Term(coef, deg);
if (data.isEmpty()) {
data.addFirst(T);
} else {
data.addLast(T);
}
}
}
public X00000000() {
super();
}
public Polynomial add(Polynomial p) {
Polynomial ans = new X00000000();
// complete this code
return ans;
}
public Polynomial subtract(Polynomial p) {
Polynomial ans = new X00000000();
// complete this code
return ans;
}
public Polynomial multiply(Polynomial p) {
Polynomial ans = new X00000000();
// complete this code
return ans;
}
public Polynomial divide(Polynomial p) throws Exception {
Polynomial ans = new X00000000();
// complete this code
return ans;
}
public Polynomial remainder(Polynomial p) throws Exception {
Polynomial ans = new X00000000();
// complete this code
return ans;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.