Skip to content

Instantly share code, notes, and snippets.

View jcbribeiro's full-sized avatar

José Carlos Bregieiro Ribeiro jcbribeiro

View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
public double evaluate() {
return isEndOfGameState() // se of jogo acabou (alguém ganhou ou o tabuleiro está cheio)
? utility() // então devolver pontuação 0, +infinito ou -infinito (consoante seja empate, o agente a ganhar ou o oponente a ganhar)
: getWinningPossibilities(agentPiece) - getWinningPossibilities(opponentPiece); // senão devolver uma pontuação de acordo com a heurística definida
}
// devolve o número de possibilidades que determinado jogador tem de ganhar a partir deste estado
private int getWinningPossibilities(char player) {
char other = player == X ? O : X;
int possibilities = 0;
public class Minimax extends GameAlgorithm {
//MINIMAX-DECISION(state) returns an action
// max = -∞
// For each a from ACTIONS(state) do
// v = MIN-VALUE(RESULT(state, a), 1)
// If (v > max) max = v; action = a
// returns action
@Override
public Action takeDecision(AgentState currentState) {
package agent;
import common.Action;
public class AlphaBeta extends GameAlgorithm {
//ALFABETA-DECISION(state) returns an action
// max = -∞
// For each a from ACTIONS(state) do
// v = MINVALUE(RESULT(state, a), max, +∞, 1)
@Override
public Solution search(Problem problem) {
statistics.reset();
stopped = false;
this.heuristic = problem.getHeuristic();
limit = heuristic.compute(problem.getInitialState());
Solution solution;
do {
@jcbribeiro
jcbribeiro / IDAStarSearch.java
Last active May 14, 2018 09:52
IDAStarSearch
@Override
public Solution search(Problem problem) {
statistics.reset();
stopped = false;
this.heuristic = problem.getHeuristic();
limit = heuristic.compute(problem.getInitialState());
Solution solution;
do {
@jcbribeiro
jcbribeiro / activity_main.xml
Created April 7, 2018 13:38
Awareness - MainActivity's layout for implementing fences.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="pt.ipleiria.awareness.MainActivity">
<LinearLayout
@jcbribeiro
jcbribeiro / JsonDeserializer -- .net DateTime to Java Date
Created December 22, 2017 12:15
Gson does not support deserialization of Microsoft's DateTime format out of the box. This custom JsonDeserializer is registered for the Date type. Gson will use it to deserialize for the Date type instead of its default. The same can be done for any other type, if you want to serialize/deserialize it in a custom way. More info: https://stackover…
// more info: https://stackoverflow.com/a/12878774
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDeserializer<Date> () {
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
// example string: "/Date(1513943979489+0000)/"
String s = json.getAsJsonPrimitive().getAsString();
// A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT
// https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
// FIX: ignore the sign, and digits after it
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="pt.ipleiria.contacts.AddActivity">
<EditText
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="pt.ipleiria.contacts.SearchActivity">
<EditText