Obliczenia brydżowe (Android)
Jacek Kowalski
2015-01-17 7a519ea493c2c38d602dcd3045da81d4d4c0ce2c
Switch to Android Studio IDE and use English as the default language.
12 files deleted
7 files renamed
17 files added
4 files modified
1571 ■■■■ changed files
.gitignore 6 ●●●●● patch | view | raw | blame | history
.idea/.name 2 ●●● patch | view | raw | blame | history
.idea/codeStyleSettings.xml 14 ●●●●● patch | view | raw | blame | history
.idea/copyright/profiles_settings.xml 4 ●●● patch | view | raw | blame | history
.idea/gradle.xml 19 ●●●●● patch | view | raw | blame | history
.idea/inspectionProfiles/Project_Default.xml 7 ●●●●● patch | view | raw | blame | history
.idea/inspectionProfiles/profiles_settings.xml 7 ●●●●● patch | view | raw | blame | history
.idea/misc.xml 21 ●●●● patch | view | raw | blame | history
.idea/modules.xml 3 ●●●● patch | view | raw | blame | history
.idea/uiDesigner.xml 125 ●●●●● patch | view | raw | blame | history
Android.iml 20 ●●●●● patch | view | raw | blame | history
AndroidManifest.xml 16 ●●●●● patch | view | raw | blame | history
Bridge.iml 21 ●●●●● patch | view | raw | blame | history
ant.properties 17 ●●●●● patch | view | raw | blame | history
app/.gitignore 1 ●●●● patch | view | raw | blame | history
app/app.iml 91 ●●●●● patch | view | raw | blame | history
app/build.gradle 24 ●●●●● patch | view | raw | blame | history
app/proguard-rules.pro 9 ●●●●● patch | view | raw | blame | history
app/src/androidTest/java/net/jacekk/bridge/ApplicationTest.java 10 ●●●●● patch | view | raw | blame | history
app/src/main/AndroidManifest.xml 12 ●●●●● patch | view | raw | blame | history
app/src/main/java/net/jacekk/bridge/BridgeCompute.java 224 ●●●●● patch | view | raw | blame | history
app/src/main/java/net/jacekk/bridge/BridgeResult.java 2 ●●● patch | view | raw | blame | history
app/src/main/java/net/jacekk/bridge/android/MainActivity.java 140 ●●●● patch | view | raw | blame | history
app/src/main/res/drawable-hdpi/icon.png patch | view | raw | blame | history
app/src/main/res/drawable-ldpi/icon.png patch | view | raw | blame | history
app/src/main/res/drawable-mdpi/icon.png patch | view | raw | blame | history
app/src/main/res/drawable-xhdpi/icon.png patch | view | raw | blame | history
app/src/main/res/drawable-xxhdpi/icon.png patch | view | raw | blame | history
app/src/main/res/layout/main.xml 195 ●●●●● patch | view | raw | blame | history
app/src/main/res/values-pl/strings.xml 37 ●●●●● patch | view | raw | blame | history
app/src/main/res/values/strings.xml 37 ●●●●● patch | view | raw | blame | history
app/src/main/res/values/styles.xml 5 ●●●●● patch | view | raw | blame | history
build.gradle 19 ●●●●● patch | view | raw | blame | history
build.xml 92 ●●●●● patch | view | raw | blame | history
gradle/wrapper/gradle-wrapper.properties 6 ●●●●● patch | view | raw | blame | history
project.properties 14 ●●●●● patch | view | raw | blame | history
res/layout/main.xml 137 ●●●●● patch | view | raw | blame | history
res/values/strings.xml 37 ●●●●● patch | view | raw | blame | history
settings.gradle 1 ●●●● patch | view | raw | blame | history
src/net/jacekk/brydz/BridgeCompute.java 196 ●●●●● patch | view | raw | blame | history
.gitignore
New file
@@ -0,0 +1,6 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
.idea/.name
@@ -1 +1 @@
Obliczenia brydżowe
Bridge
.idea/codeStyleSettings.xml
File was deleted
.idea/copyright/profiles_settings.xml
@@ -1,5 +1,3 @@
<component name="CopyrightManager">
  <settings default="">
    <module2copyright />
  </settings>
  <settings default="" />
</component>
.idea/gradle.xml
New file
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="distributionType" value="DEFAULT_WRAPPED" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="gradleHome" value="$APPLICATION_HOME_DIR$/plugins/gradle" />
        <option name="modules">
          <set>
            <option value="$PROJECT_DIR$" />
            <option value="$PROJECT_DIR$/app" />
          </set>
        </option>
      </GradleProjectSettings>
    </option>
  </component>
</project>
.idea/inspectionProfiles/Project_Default.xml
File was deleted
.idea/inspectionProfiles/profiles_settings.xml
File was deleted
.idea/misc.xml
@@ -1,10 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="EntryPointsManager">
    <entry_points version="2.0" />
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/classes" />
  </component>
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="Android SDK" project-jdk-type="Android SDK">
    <output url="file://$PROJECT_DIR$/out" />
  <component name="masterDetails">
    <states>
      <state key="ProjectJDKs.UI">
        <settings>
          <last-edited>1.7</last-edited>
          <splitter-proportions>
            <option name="proportions">
              <list>
                <option value="0.2" />
              </list>
            </option>
          </splitter-proportions>
        </settings>
      </state>
    </states>
  </component>
</project>
.idea/modules.xml
@@ -2,7 +2,8 @@
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/Android.iml" filepath="$PROJECT_DIR$/Android.iml" />
      <module fileurl="file://$PROJECT_DIR$/Bridge.iml" filepath="$PROJECT_DIR$/Bridge.iml" />
      <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
    </modules>
  </component>
</project>
.idea/uiDesigner.xml
File was deleted
Android.iml
File was deleted
AndroidManifest.xml
File was deleted
Bridge.iml
New file
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
  <component name="FacetManager">
    <facet type="java-gradle" name="Java-Gradle">
      <configuration>
        <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
      </configuration>
    </facet>
  </component>
  <component name="NewModuleRootManager" inherit-compiler-output="false">
    <output url="file://$MODULE_DIR$/build/classes/main" />
    <output-test url="file://$MODULE_DIR$/build/classes/test" />
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <excludeFolder url="file://$MODULE_DIR$/.gradle" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>
ant.properties
File was deleted
app/.gitignore
New file
@@ -0,0 +1 @@
/build
app/app.iml
New file
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
  <component name="FacetManager">
    <facet type="android-gradle" name="Android-Gradle">
      <configuration>
        <option name="GRADLE_PROJECT_PATH" value=":app" />
      </configuration>
    </facet>
    <facet type="android" name="Android">
      <configuration>
        <option name="SELECTED_BUILD_VARIANT" value="debug" />
        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
        <option name="ALLOW_USER_CONFIGURATION" value="false" />
        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
      </configuration>
    </facet>
  </component>
  <component name="NewModuleRootManager" inherit-compiler-output="false">
    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
    </content>
    <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
    <orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
    <orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
  </component>
</module>
app/build.gradle
New file
@@ -0,0 +1,24 @@
apply plugin: 'com.android.application'
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        applicationId "net.jacekk.bridge"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}
app/proguard-rules.pro
File was renamed from proguard-project.txt
@@ -1,11 +1,8 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
# in /home/jacek/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html
app/src/androidTest/java/net/jacekk/bridge/ApplicationTest.java
New file
@@ -0,0 +1,10 @@
package net.jacekk.bridge;
import android.app.Application;
import android.test.ApplicationTestCase;
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }
}
app/src/main/AndroidManifest.xml
New file
@@ -0,0 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.jacekk.bridge">
    <application android:allowBackup="true" android:label="@string/app_name"
        android:icon="@drawable/icon" android:theme="@style/AppTheme">
        <activity android:name="net.jacekk.bridge.android.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
app/src/main/java/net/jacekk/bridge/BridgeCompute.java
New file
@@ -0,0 +1,224 @@
package net.jacekk.bridge;
public class BridgeCompute {
    // Points for tricks
    protected int tricks[][] = {
            {0, 20, 40, 60, 80, 100, 120, 140},  // minor suits
            {0, 30, 60, 90, 120, 150, 180, 210}, // major suits
            {0, 40, 70, 100, 130, 160, 190, 220} // no trump
    };
    // Points for [i] undertricks
    protected int undertricks[][][] = {
            {   // non vulnerable
                    {0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650},            // normal
                    {0, 100, 300, 500, 700, 900, 1100, 1300, 1500, 1700, 1900, 2100, 2300, 2500},   // double
                    {0, 200, 600, 1000, 1400, 1800, 2200, 2600, 3000, 3400, 3800, 4200, 4600, 5000} // redouble
            },
            {   // vulnerable
                    {0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300},       // normal
                    {0, 200, 500, 800, 1100, 1400, 1700, 2000, 2300, 2600, 2900, 3200, 3500, 3800}, // double
                    {0, 400, 1000, 1600, 2200, 2800, 3400, 4000, 4600, 5200, 5800, 6400, 7000, 7600}// redouble
            }
    };
    // Points required per Milton Work Point Count
    protected int PC[][][] = {
            {   // We: non vulnerable, they: non vulnerable
                    {-1400, -1400, -1400, -1400, -1200, -1100, -1000,  -900,  -700,  -600,  -490,
                             -460,  -430,  -400,  -350,  -300,  -200,  -110,   -70,   -50,     0,
                               50,    70,   110,   200,   300,   350,   400,   430,   460,   490,
                              600,   700,   900,  1000,  1100,  1200,  1400,  1400,  1400,  1400},
                // We: non vulnerable, they: vulnerable
                    {-2100, -2100, -2100, -2100, -1800, -1650, -1500, -1350, -1050,  -800,  -690,
                             -660,  -630,  -600,  -520,  -440,  -290,  -110,   -70,   -50,     0,
                               50,    70,   110,   200,   300,   350,   400,   430,   460,   490,
                              600,   700,   900,  1000,  1100,  1200,  1400,  1400,  1400,  1400}
            },
            {   // We: vulnerable, they: non vulnerable
                    {-1400, -1400, -1400, -1400, -1200, -1100, -1000,  -900,  -700,  -600,  -490,
                             -460,  -430,  -400,  -350,  -300,  -200,  -110,   -70,   -50,     0,
                               50,    70,   110,   290,   440,   520,   600,   630,   660,   690,
                              800,  1050,  1350,  1500,  1650,  1800,  2100,  2100,  2100,  2100},
                // We: vulnerable, they: vulnerable
                    {-2100, -2100, -2100, -2100, -1800, -1650, -1500, -1350, -1050,  -800,  -690,
                             -660,  -630,  -600,  -520,  -440,  -290,  -110,   -70,   -50,     0,
                               50,    70,   110,   290,   440,   520,   600,   630,   660,   690,
                              800,  1050,  1350,  1500,  1650,  1800,  2100,  2100,  2100,  2100}
            }
    };
    // Points required for [i] IMPs
    protected int IMPs[] = { 0, 20, 50, 90, 130, 170, 220, 270, 320, 370, 430, 500, 600, 750, 900,
            1100, 1300, 1500, 1750, 2000, 2250, 2500, 3000, 3500, 4000, 9999999};
    // percent* properties are related to scoring system by Adam Królik
    // See: http://www.gplewniak.republika.pl/strony/zapis.html
    // Points received - [i] used to access row from percent variable
    protected int percent_points[][] = {
            {0, 50, 90, 120, 150, 180, 210, 300, 400, 430, 460, 490, 520, 800, 920, 940, 980, 990,
                    1020, 1400, 1440, 1520, 1530, 9999999}, // non vulnerable
            {0, 50, 90, 120, 150, 180, 210, 500, 600, 360, 660, 690, 720, 810, 1370, 1390, 1430,
                    1440, 1470, 1700, 2000, 2220, 2230, 9999999} // vulnerable
    };
    // Work Point Count - [i] used to access column from property percent
    protected int percent_PC[] = {0, 6, 10, 16, 21, 25, 31, 35, 9999999};
    // Percent score per [i] - points scored, [j] - PC had
    protected int percent[][] = {
            {-1, -1, -1, 50, 44, 26, 8, 0},
            {83, 74, 65, 56, 47, 29, 11, 0},
            {86, 77, 68, 59, 50, 32, 14, 0},
            {89, 80, 71, 62, 53, 35, 17, 0},
            {92, 83, 74, 65, 56, 38, 20, 2},
            {95, 86, 77, 68, 59, 41, 23, 5},
            {98, 89, 80, 71, 62, 44, 26, 8},
            {100, 92, 83, 74, 65, 47, 29, 11},
            {100, 95, 86, 77, 68, 50, 32, 14},
            {100, 98, 89, 80, 71, 53, 35, 17},
            {100, 100, 92, 83, 74, 56, 38, 20},
            {100, 100, 95, 86, 77, 59, 41, 23},
            {100, 100, 98, 89, 80, 62, 44, 26},
            {100, 100, 100, 92, 83, 65, 47, 29},
            {100, 100, 100, 95, 86, 68, 50, 32},
            {100, 100, 100, 98, 89, 71, 53, 35},
            {100, 100, 100, 100, 92, 74, 56, 38},
            {100, 100, 100, 100, 95, 77, 59, 41},
            {100, 100, 100, 100, 98, 80, 62, 44},
            {100, 100, 100, 100, 100, 83, 65, 47},
            {100, 100, 100, 100, 100, 86, 68, 50},
            {100, 100, 100, 100, 100, 89, 71, 53},
            {100, 100, 100, 100, 100, 100, 95, 90}
    };
    // Finds IMP score for points given (using IMPs property)
    protected int IMP(int points) {
        int i = 0;
        while (IMPs[i + 1] <= points) {
            i++;
        }
        return i;
    }
    // Finds percent score for data given (using percent* properties)
    protected int percent(int PC, int points, int vulnerability) {
        int points_i = 0;
        int PC_i = 0;
        while (this.percent_points[vulnerability][points_i + 1] <= points) {
            points_i++;
        }
        while (this.percent_PC[PC_i + 1] <= PC) {
            PC_i++;
        }
        return this.percent[points_i][PC_i];
    }
    public BridgeResult compute(int bid, int color, int dbl, int vulnerability, int PC, int tricks) {
        BridgeResult result = new BridgeResult();
        int weVulnerable = vulnerability / 2;
        int theyVulnerable = vulnerability % 2;
        // 4 passes
        if (bid == 0) {
            result.pointsFor = BridgeResult.PointsFor.Them;
            result.points = this.PC[weVulnerable][theyVulnerable][PC];
            result.IMPs = this.IMP(result.points);
            result.percent = 100 - this.percent(PC, 0, weVulnerable);
            return result;
        }
        // Result in points
        int resultPoints;
        // Points for tricks
        int pointsForTricks;
        // Result minus points required, according to PC property
        int pointsForScoring;
        // Number of overtricks (or undertricks if negative)
        int additionalTricks = tricks - 6 - bid;
        // Double/redouble multiplier
        int multiplier = dbl + 1;
        if (multiplier == 3) {
            multiplier = 4;
        }
        // Contract made
        if (additionalTricks >= 0) {
            // Ordinary contract
            if (multiplier == 1) {
                pointsForTricks = this.tricks[color][bid];
                resultPoints = this.tricks[color][tricks - 6];
            }
            // Contract doubled/redoubled
            else {
                pointsForTricks = this.tricks[color][bid] * multiplier;
                resultPoints = pointsForTricks;
                // Bonus for winning doubled/redoubled contract
                resultPoints += 25 * multiplier;
                // For overtricks
                resultPoints += additionalTricks * (weVulnerable == 0 ? 50 : 100) * multiplier;
            }
            if (bid == 6) {
                // Bonus for small slam
                resultPoints += (weVulnerable == 0 ? 500 : 750);
            } else if (bid == 7) {
                // Bonus for grand slam
                resultPoints += (weVulnerable == 0 ? 1000 : 1500);
            }
            if (pointsForTricks >= 100) {
                // Bonus for game
                resultPoints += (weVulnerable == 0 ? 300 : 500);
            } else {
                // Bonus for part-game
                resultPoints += 50;
            }
        }
        // Contract defeated
        else {
            // Points for undertricks (for defending side)
            resultPoints = -1 * this.undertricks[weVulnerable][dbl][-1 * additionalTricks];
        }
        // Deduct points required
        pointsForScoring = resultPoints - this.PC[weVulnerable][theyVulnerable][PC];
        // Score for defeaters
        if (pointsForScoring < 0) {
            result.pointsFor = BridgeResult.PointsFor.Them;
            result.pointsBefore = -1 * resultPoints;
            result.points = -1 * pointsForScoring;
            result.IMPs = IMP(result.points);
            if (resultPoints < 0) {
                result.percent = percent(40 - PC, -1 * resultPoints, theyVulnerable);
            } else {
                result.percent = 100 - percent(PC, resultPoints, weVulnerable);
            }
        }
        // Score for declarers
        else {
            result.pointsFor = BridgeResult.PointsFor.Us;
            result.pointsBefore = resultPoints;
            result.points = pointsForScoring;
            result.IMPs = IMP(result.points);
            if (resultPoints > 0) {
                result.percent = percent(PC, resultPoints, weVulnerable);
            } else {
                result.percent = 100 - percent(40 - PC, -1 * resultPoints, theyVulnerable);
            }
        }
        return result;
    }
}
app/src/main/java/net/jacekk/bridge/BridgeResult.java
File was renamed from src/net/jacekk/brydz/BridgeResult.java
@@ -1,4 +1,4 @@
package net.jacekk.brydz;
package net.jacekk.bridge;
public class BridgeResult {
    public enum PointsFor {
app/src/main/java/net/jacekk/bridge/android/MainActivity.java
File was renamed from src/net/jacekk/brydz/android/MainActivity.java
@@ -1,4 +1,4 @@
package net.jacekk.brydz.android;
package net.jacekk.bridge.android;
import android.app.Activity;
import android.os.Bundle;
@@ -9,25 +9,27 @@
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;
import net.jacekk.brydz.BridgeCompute;
import net.jacekk.brydz.BridgeResult;
import net.jacekk.bridge.R;
import net.jacekk.bridge.BridgeCompute;
import net.jacekk.bridge.BridgeResult;
public class MainActivity extends Activity {
    private SeekBar BidSlider;
    private TextView BidText;
    private ToggleButton CDToggle;
    private ToggleButton HSToggle;
    private ToggleButton NTToggle;
    private ToggleButton MinorSuitsToggle;
    private ToggleButton MajorSuitsToggle;
    private ToggleButton NoTrumpToggle;
    private ToggleButton NormToggle;
    private ToggleButton DblToggle;
    private ToggleButton ReDblToggle;
    private ToggleButton ContractToggle;
    private ToggleButton DoubleToggle;
    private ToggleButton RedoubleToggle;
    private ToggleButton BBToggle;
    private ToggleButton BAToggle;
    private ToggleButton ABToggle;
    private ToggleButton AAToggle;
    private ToggleButton NNToggle;
    private ToggleButton NVToggle;
    private ToggleButton VNToggle;
    private ToggleButton VVToggle;
    private EditText PCInput;
    private EditText TricksInput;
@@ -53,23 +55,23 @@
        BidSlider = (SeekBar) findViewById(R.id.BidSlider);
        BidText = (TextView) findViewById(R.id.BidText);
        CDToggle = (ToggleButton) findViewById(R.id.CDToggle);
        HSToggle = (ToggleButton) findViewById(R.id.HSToggle);
        NTToggle = (ToggleButton) findViewById(R.id.NTToggle);
        MinorSuitsToggle = (ToggleButton) findViewById(R.id.MinorSuitsToggle);
        MajorSuitsToggle = (ToggleButton) findViewById(R.id.MajorSuitsToggle);
        NoTrumpToggle = (ToggleButton) findViewById(R.id.NoTrumpToggle);
        NormToggle = (ToggleButton) findViewById(R.id.NormToggle);
        DblToggle = (ToggleButton) findViewById(R.id.DblToggle);
        ReDblToggle = (ToggleButton) findViewById(R.id.ReDblToggle);
        ContractToggle = (ToggleButton) findViewById(R.id.ContractToggle);
        DoubleToggle = (ToggleButton) findViewById(R.id.DoubleToggle);
        RedoubleToggle = (ToggleButton) findViewById(R.id.RedoubleToggle);
        BBToggle = (ToggleButton) findViewById(R.id.BBToggle);
        BAToggle = (ToggleButton) findViewById(R.id.BAToggle);
        ABToggle = (ToggleButton) findViewById(R.id.ABToggle);
        AAToggle = (ToggleButton) findViewById(R.id.AAToggle);
        NNToggle = (ToggleButton) findViewById(R.id.NNToggle);
        NVToggle = (ToggleButton) findViewById(R.id.NVToggle);
        VNToggle = (ToggleButton) findViewById(R.id.VNToggle);
        VVToggle = (ToggleButton) findViewById(R.id.VVToggle);
        PCInput = (EditText) findViewById(R.id.PCInput);
        TricksInput = (EditText) findViewById(R.id.TricksInput);
        resultText = (TextView) findViewById(R.id.resultText);
        resultText = (TextView) findViewById(R.id.ResultsText);
        BidSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
@@ -92,62 +94,62 @@
            public void onClick(View view) {
                ToggleButton toggle = (ToggleButton) view;
                if (!toggle.equals(CDToggle))
                    CDToggle.setChecked(false);
                if (!toggle.equals(HSToggle))
                    HSToggle.setChecked(false);
                if (!toggle.equals(NTToggle))
                    NTToggle.setChecked(false);
                if (!toggle.equals(MinorSuitsToggle))
                    MinorSuitsToggle.setChecked(false);
                if (!toggle.equals(MajorSuitsToggle))
                    MajorSuitsToggle.setChecked(false);
                if (!toggle.equals(NoTrumpToggle))
                    NoTrumpToggle.setChecked(false);
                updateResults();
            }
        };
        CDToggle.setOnClickListener(colorClickListener);
        HSToggle.setOnClickListener(colorClickListener);
        NTToggle.setOnClickListener(colorClickListener);
        MinorSuitsToggle.setOnClickListener(colorClickListener);
        MajorSuitsToggle.setOnClickListener(colorClickListener);
        NoTrumpToggle.setOnClickListener(colorClickListener);
        ToggleButton.OnClickListener bidClickListener = new ToggleButton.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToggleButton toggle = (ToggleButton) view;
                if (!toggle.equals(NormToggle))
                    NormToggle.setChecked(false);
                if (!toggle.equals(DblToggle))
                    DblToggle.setChecked(false);
                if (!toggle.equals(ReDblToggle))
                    ReDblToggle.setChecked(false);
                if (!toggle.equals(ContractToggle))
                    ContractToggle.setChecked(false);
                if (!toggle.equals(DoubleToggle))
                    DoubleToggle.setChecked(false);
                if (!toggle.equals(RedoubleToggle))
                    RedoubleToggle.setChecked(false);
                updateResults();
            }
        };
        NormToggle.setOnClickListener(bidClickListener);
        DblToggle.setOnClickListener(bidClickListener);
        ReDblToggle.setOnClickListener(bidClickListener);
        ContractToggle.setOnClickListener(bidClickListener);
        DoubleToggle.setOnClickListener(bidClickListener);
        RedoubleToggle.setOnClickListener(bidClickListener);
        ToggleButton.OnClickListener baClickListener = new ToggleButton.OnClickListener() {
            public void onClick(View view) {
                ToggleButton toggle = (ToggleButton) view;
                if (!toggle.equals(AAToggle))
                    AAToggle.setChecked(false);
                if (!toggle.equals(ABToggle))
                    ABToggle.setChecked(false);
                if (!toggle.equals(BAToggle))
                    BAToggle.setChecked(false);
                if (!toggle.equals(BBToggle))
                    BBToggle.setChecked(false);
                if (!toggle.equals(VVToggle))
                    VVToggle.setChecked(false);
                if (!toggle.equals(VNToggle))
                    VNToggle.setChecked(false);
                if (!toggle.equals(NVToggle))
                    NVToggle.setChecked(false);
                if (!toggle.equals(NNToggle))
                    NNToggle.setChecked(false);
                updateResults();
            }
        };
        AAToggle.setOnClickListener(baClickListener);
        ABToggle.setOnClickListener(baClickListener);
        BAToggle.setOnClickListener(baClickListener);
        BBToggle.setOnClickListener(baClickListener);
        VVToggle.setOnClickListener(baClickListener);
        VNToggle.setOnClickListener(baClickListener);
        NVToggle.setOnClickListener(baClickListener);
        NNToggle.setOnClickListener(baClickListener);
        PCInput.addTextChangedListener(
                new TextWatcher() {
@@ -188,35 +190,35 @@
        int bid = BidSlider.getProgress();
        int color = 0;
        if (HSToggle.isChecked())
        if (MajorSuitsToggle.isChecked())
            color = 1;
        if (NTToggle.isChecked())
        if (NoTrumpToggle.isChecked())
            color = 2;
        int dbl = 0;
        if (DblToggle.isChecked())
        if (DoubleToggle.isChecked())
            dbl = 1;
        if (ReDblToggle.isChecked())
        if (RedoubleToggle.isChecked())
            dbl = 2;
        int baba = 0;
        if (BAToggle.isChecked())
            baba = 1;
        if (ABToggle.isChecked())
            baba = 2;
        if (AAToggle.isChecked())
            baba = 3;
        int vulnerability = 0;
        if (NVToggle.isChecked())
            vulnerability = 1;
        if (VNToggle.isChecked())
            vulnerability = 2;
        if (VVToggle.isChecked())
            vulnerability = 3;
        int PC = -1;
        try {
            PC = Integer.parseInt(PCInput.getText().toString());
        } catch (NumberFormatException e) {
        } catch (NumberFormatException ignored) {
        }
        int tricks = -1;
        try {
            tricks = Integer.parseInt(TricksInput.getText().toString());
        } catch (NumberFormatException e) {
        } catch (NumberFormatException ignored) {
        }
        if (bid < 0 || bid > 7) {
@@ -234,7 +236,7 @@
            return;
        }
        if (baba < 0 || baba > 3) {
        if (vulnerability < 0 || vulnerability > 3) {
            resultText.setText(getString(R.string.invalid_baba));
            return;
        }
@@ -254,7 +256,7 @@
            return;
        }
        BridgeResult result = bridgeCompute.compute(bid, color, dbl, baba, PC, tricks);
        BridgeResult result = bridgeCompute.compute(bid, color, dbl, vulnerability, PC, tricks);
        resultText.setText(
                (result.pointsFor == BridgeResult.PointsFor.Us ? getString(R.string.result_for_us) : getString(R.string.result_for_them)) +
                        "\n" + getString(R.string.result_pts_wo_pc) + " " + result.pointsBefore +
app/src/main/res/drawable-hdpi/icon.png

app/src/main/res/drawable-ldpi/icon.png

app/src/main/res/drawable-mdpi/icon.png

app/src/main/res/drawable-xhdpi/icon.png

app/src/main/res/drawable-xxhdpi/icon.png
app/src/main/res/layout/main.xml
New file
@@ -0,0 +1,195 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="10dp"
    android:orientation="vertical">
    <SeekBar
        android:id="@+id/BidSlider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:max="7" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:weightSum="1">
        <TextView
            android:id="@+id/BidText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="0.25"
            android:text="0"
            android:textAlignment="gravity"
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <ToggleButton
            android:id="@+id/MinorSuitsToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:checked="true"
            android:text="@string/minor_suits"
            android:textOff="@string/minor_suits"
            android:textOn="@string/minor_suits" />
        <ToggleButton
            android:id="@+id/MajorSuitsToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:checked="false"
            android:text="@string/major_suits"
            android:textOff="@string/major_suits"
            android:textOn="@string/major_suits" />
        <ToggleButton
            android:id="@+id/NoTrumpToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:checked="false"
            android:text="@string/no_trumph"
            android:textOff="@string/no_trumph"
            android:textOn="@string/no_trumph" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ToggleButton
            android:id="@+id/ContractToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="true"
            android:text="@string/bid_normal"
            android:textOff="@string/bid_normal"
            android:textOn="@string/bid_normal" />
        <ToggleButton
            android:id="@+id/DoubleToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="false"
            android:text="@string/bid_double"
            android:textOff="@string/bid_double"
            android:textOn="@string/bid_double" />
        <ToggleButton
            android:id="@+id/RedoubleToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="false"
            android:text="@string/bid_redouble"
            android:textOff="@string/bid_redouble"
            android:textOn="@string/bid_redouble" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ToggleButton
            android:id="@+id/NNToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="true"
            android:text="@string/before_before"
            android:textOff="@string/before_before"
            android:textOn="@string/before_before" />
        <ToggleButton
            android:id="@+id/NVToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="false"
            android:text="@string/before_after"
            android:textOff="@string/before_after"
            android:textOn="@string/before_after" />
        <ToggleButton
            android:id="@+id/VNToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="false"
            android:text="@string/after_before"
            android:textOff="@string/after_before"
            android:textOn="@string/after_before" />
        <ToggleButton
            android:id="@+id/VVToggle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="false"
            android:text="@string/after_after"
            android:textOff="@string/after_after"
            android:textOn="@string/after_after" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/PCText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:labelFor="@+id/PCInput"
            android:text="@string/pc"
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <EditText
            android:id="@+id/PCInput"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="4"
            android:inputType="number" />
        <Space
            android:layout_width="20dp"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/TricksText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:labelFor="@+id/TricksInput"
            android:text="@string/tricks"
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <EditText
            android:id="@+id/TricksInput"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="4"
            android:inputType="number" />
    </LinearLayout>
    <TextView
        android:id="@+id/ResultsText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:text="@string/invalid_empty"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
app/src/main/res/values-pl/strings.xml
New file
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Obliczenia brydżowe</string>
    <string name="minor_suits">♣ / ♦</string>
    <string name="major_suits">♥ / ♠</string>
    <string name="no_trumph">NT</string>
    <string name="before_before">przed/przed</string>
    <string name="before_after">przed/po</string>
    <string name="after_before">po/przed</string>
    <string name="after_after">po/po</string>
    <string name="bid_normal">norm.</string>
    <string name="bid_double">ktr.</string>
    <string name="bid_redouble">rektr.</string>
    <string name="pc">PC:</string>
    <string name="tricks">Lew:</string>
    <string name="invalid_empty">Podaj wszystkie dane.</string>
    <string name="invalid_bid">Niepoprawny kontrakt.</string>
    <string name="invalid_color">Niepoprawny kolor kontraktu.</string>
    <string name="invalid_dbl">Niepoprawna informacja o kontrze.</string>
    <string name="invalid_baba">Niepoprawna informacja o partii.</string>
    <string name="invalid_pc">Niepoprawna ilość punktów.</string>
    <string name="invalid_tricks">Niepoprawna ilość wziętych lew.</string>
    <string name="invalid_pass">Przy czterech pasach podaj większą liczę punktów.</string>
    <string name="result_for_us">Zapis dla rozgrywających.</string>
    <string name="result_for_them">Zapis dla przeciwników.</string>
    <string name="result_pts_wo_pc">Punktów (bez PC):</string>
    <string name="result_pts">Punktów (z PC):</string>
    <string name="result_imps">IMP-ów:</string>
    <string name="result_percent">Procent:</string>
</resources>
app/src/main/res/values/strings.xml
New file
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Bridge scoring</string>
    <string name="minor_suits">♣ / ♦</string>
    <string name="major_suits">♥ / ♠</string>
    <string name="no_trumph">NT</string>
    <string name="before_before">non./non</string>
    <string name="before_after">non./vuln.</string>
    <string name="after_before">vunl./non.</string>
    <string name="after_after">vuln./vuln.</string>
    <string name="bid_normal">norm.</string>
    <string name="bid_double">dbl.</string>
    <string name="bid_redouble">redbl.</string>
    <string name="pc">PC:</string>
    <string name="tricks">Tricks:</string>
    <string name="invalid_empty">Enter required information.</string>
    <string name="invalid_bid">Invalid contract level.</string>
    <string name="invalid_color">Invalid contract color.</string>
    <string name="invalid_dbl">Invalid information about doubling/redoubling.</string>
    <string name="invalid_baba">Invalid information about vulnerability.</string>
    <string name="invalid_pc">Invalid number for Milton Work Point Count.</string>
    <string name="invalid_tricks">Invalid number of tricks taken.</string>
    <string name="invalid_pass">For four passes enter data for side with more PCs.</string>
    <string name="result_for_us">Score for declaring side.</string>
    <string name="result_for_them">Score for defending side.</string>
    <string name="result_pts_wo_pc">Points (excl. PC):</string>
    <string name="result_pts">Points (incl. PC):</string>
    <string name="result_imps">IMPs:</string>
    <string name="result_percent">Percent:</string>
</resources>
app/src/main/res/values/styles.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Holo">
    </style>
</resources>
build.gradle
New file
@@ -0,0 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
build.xml
File was deleted
gradle/wrapper/gradle-wrapper.properties
New file
@@ -0,0 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
project.properties
File was deleted
res/layout/main.xml
File was deleted
res/values/strings.xml
File was deleted
settings.gradle
New file
@@ -0,0 +1 @@
include ':app'
src/net/jacekk/brydz/BridgeCompute.java
File was deleted