Skip to content

Commit af0d760

Browse files
committed
Update to korge 6.0
1 parent 1975dbb commit af0d760

File tree

33 files changed

+1430
-2074
lines changed

33 files changed

+1430
-2074
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Carlos Ballesteros Velasco
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
# 2048 AI
1+
# Korge Hello World and Template
22

3-
2048 game AI implemented in Kotlin with
3+
This is a Hello World and Template for the KorGe game engine. Using gradle with kotlin-dsl.
4+
You can open this project in IntelliJ IDEA by opening the folder or the build.gradle.kts file.
45

5-
- [Korge](https://korge.org) game engine
6-
- 64-bit board representation, [Expectimax](https://en.wikipedia.org/wiki/Expectiminimax)
7-
search algorithm, precomputed tables for moves and position evaluation and other
8-
optimizations (from [here](https://github.com/nneonneo/2048-ai))
9-
- Kotlin/JS or WASM inside web-workers for multi-threading in the browser
6+
You can find this template at GitHub: <https://github.com/korlibs/korge-hello-world>
107

11-
This project evolved from the
12-
introductory [tutorial](https://blog.korge.org/korge-tutorial-writing-2048-game-step-0) to
13-
the Korge engine. Then I added the AI which on JVM now can search to up to 10 million moves
14-
per second with depths up to 10 on the M1 Macbook.
158

16-
Web version compiled with Kotlin/JS is here: [2048.marchuk.io](2048.marchuk.io).
17-
Kotlin/WASM uses experimetnal [Web Assembly garbage collection](https://github.com/WebAssembly/gc) and if it is not supported in the browser the game falls back to JS-only implementation of Expectimax search.
18-
For now, to achieve maximum performance in the web version use Chrome browser with `chrome://flags/#enable-webassembly-garbage-collection` flag enabled.
9+
You can find the KorGE documentation here: <https://docs.korge.org/korge/>

build.gradle.kts

+35-176
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,53 @@
1-
@file:Suppress("OPT_IN_USAGE")
2-
31
import korlibs.korge.gradle.BuildVersions
4-
import korlibs.korge.gradle.coroutinesVersion
5-
import korlibs.korge.gradle.kdsVersion
6-
import korlibs.korge.gradle.klockVersion
7-
import korlibs.korge.gradle.kmemVersion
8-
import korlibs.korge.gradle.korauVersion
9-
import korlibs.korge.gradle.korgwVersion
10-
import korlibs.korge.gradle.korimVersion
11-
import korlibs.korge.gradle.korioVersion
12-
import korlibs.korge.gradle.kormaVersion
13-
import korlibs.korge.gradle.kryptoVersion
14-
import korlibs.korge.gradle.util.staticHttpServer
15-
import kotlinx.benchmark.gradle.BenchmarksExtension
16-
import kotlinx.benchmark.gradle.KotlinJvmBenchmarkTarget
17-
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
2+
import korlibs.korge.gradle.korge
183

194
plugins {
20-
id("com.soywiz.korge")
21-
id("org.jetbrains.kotlin.plugin.allopen")
22-
id("org.jetbrains.kotlinx.benchmark")
23-
}
24-
25-
val korgeVersion: String by project
26-
27-
allOpen {
28-
annotation("org.openjdk.jmh.annotations.State")
5+
alias(libs.plugins.korge)
296
}
307

31-
val benchmarksExtension: BenchmarksExtension = the<BenchmarksExtension>()
32-
338
korge {
34-
id = "io.github.smaugfm.game2048"
35-
name = "game2048"
36-
esbuildVersion = "0.17.18"
37-
jvmMainClassName = "io.github.smaugfm.game2048.MainKt"
9+
id = "io.github.smaugfm.game2048"
10+
name = "game2048"
11+
skipDeps = true
12+
13+
jvmMainClassName = "io.github.smaugfm.game2048.MainKt"
14+
entrypoint("main", "io.github.smaugfm.game2048.MainKt")
3815

39-
targetJvm()
40-
targetJs()
16+
targetJvm()
17+
// targetJs()
18+
// targetWasmJs()
19+
serializationJson()
4120
}
4221

4322
afterEvaluate {
44-
project.configurations
45-
.filter { it.name.startsWith("commonMain") }
46-
.forEach { conf ->
47-
conf.dependencies
48-
.removeIf {
49-
it.group?.startsWith("com.soywiz") == true ||
50-
it.group?.startsWith("korlibs") == true ||
51-
(it.group == "org.jetbrains.kotlinx" && it.name == "kotlinx-coroutines-core") ||
52-
(it.group == "org.jetbrains.kotlinx" && it.name == "kotlinx-serialization-json")
53-
}
23+
project.configurations
24+
.filter { it.name.startsWith("commonMain") }
25+
.forEach { conf ->
26+
conf.dependencies
27+
.removeIf {
28+
it.group?.startsWith("com.soywiz") == true ||
29+
it.group?.startsWith("korlibs") == true ||
30+
(it.group == "org.jetbrains.kotlinx" && it.name == "kotlinx-coroutines-core") ||
31+
(it.group == "org.jetbrains.kotlinx" && it.name == "kotlinx-serialization-json")
5432
}
33+
}
5534
}
5635

5736
kotlin {
58-
targets {
59-
jvm {
60-
val benchmarkCompilation = compilations
61-
.create("benchmark")
62-
63-
benchmarksExtension.targets.add(
64-
KotlinJvmBenchmarkTarget(
65-
extension = benchmarksExtension,
66-
name = "jvm",
67-
compilation = benchmarkCompilation
68-
).apply {
69-
val jmhVersion: String by project
70-
this.jmhVersion = jmhVersion
71-
}
72-
)
73-
}
74-
fun KotlinJsTargetDsl.configureJsOrWasm() {
75-
fun snakeToDashes(s: String) =
76-
s.replace("\\B[A-Z]".toRegex()) {
77-
"-${it.value}"
78-
}.toLowerCase()
79-
80-
binaries.executable()
81-
val targetName = this@configureJsOrWasm.name
82-
browser {
83-
webpackTask {
84-
outputFileName = "${snakeToDashes(targetName)}.js"
85-
}
86-
distribution {
87-
name = targetName
88-
}
89-
}
90-
}
91-
wasm("wasmTest") {
92-
configureJsOrWasm()
93-
}
94-
js("jsWorker", IR) {
95-
configureJsOrWasm()
96-
}
97-
wasm("wasmWorker") {
98-
configureJsOrWasm()
99-
}
37+
sourceSets {
38+
val commonMain by getting
39+
val commonKorge by creating {
40+
dependsOn(commonMain)
41+
dependencies {
42+
implementation("com.soywiz.korge:korge-core:${BuildVersions.KORGE}")
43+
implementation("com.soywiz.korge:korge:${BuildVersions.KORGE}")
44+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${BuildVersions.KOTLIN_SERIALIZATION}")
45+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${BuildVersions.COROUTINES}")
46+
}
10047
}
101-
sourceSets {
102-
all {
103-
languageSettings.optIn("kotlin.ExperimentalUnsignedTypes")
104-
languageSettings.optIn("kotlin.time.ExperimentalTime")
105-
}
106-
val commonMain by getting
107-
val commonKorge by creating {
108-
dependsOn(commonMain)
109-
dependencies {
110-
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${BuildVersions.KOTLIN_SERIALIZATION}")
111-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
112-
implementation("com.soywiz.korlibs.klock:klock:${klockVersion}")
113-
implementation("com.soywiz.korlibs.kmem:kmem:${kmemVersion}")
114-
implementation("com.soywiz.korlibs.kds:kds:${kdsVersion}")
115-
implementation("com.soywiz.korlibs.krypto:krypto:${kryptoVersion}")
116-
implementation("com.soywiz.korlibs.korge2:korge:${korgeVersion}")
117-
implementation("com.soywiz.korlibs.korma:korma:${kormaVersion}")
118-
implementation("com.soywiz.korlibs.korio:korio:${korioVersion}")
119-
implementation("com.soywiz.korlibs.korim:korim:${korimVersion}")
120-
implementation("com.soywiz.korlibs.korau:korau:${korauVersion}")
121-
implementation("com.soywiz.korlibs.korgw:korgw:${korgwVersion}")
122-
}
123-
}
124-
val commonBenchmark by creating {
125-
dependsOn(commonMain)
126-
dependencies {
127-
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.7")
128-
}
129-
}
130-
val jsMain by getting {
131-
dependsOn(commonKorge)
132-
// Make gradle to copy the *.js and *.wasm files to the output dir for the
133-
// main js target
134-
resources.srcDirs("./build/jsWorker")
135-
resources.srcDirs("./build/wasmWorker")
136-
resources.srcDirs("./build/wasmTest")
137-
}
138-
val jvmMain by getting {
139-
dependsOn(commonKorge)
140-
}
141-
val jvmBenchmark by getting {
142-
dependsOn(commonBenchmark)
143-
dependsOn(jvmMain)
144-
}
145-
val jsWorkerMain by getting
146-
val wasmWorkerMain by getting {
147-
dependencies {
148-
// For the hacks to work.
149-
// See ./webpack.config.d/wasm-worker.webpack.config.js
150-
implementation(npm("copy-webpack-plugin", "11.0.0"))
151-
implementation(npm("string-replace-loader", "3.1.0"))
152-
}
153-
}
154-
val wasmTestMain by getting {
155-
dependencies {
156-
implementation(npm("copy-webpack-plugin", "11.0.0"))
157-
implementation(npm("string-replace-loader", "3.1.0"))
158-
}
159-
}
48+
val jvmMain by getting {
49+
dependsOn(commonKorge)
16050
}
51+
}
16152
}
16253

163-
tasks {
164-
// Make main js target be dependent on wasm targets
165-
getByName("jsProcessResources")
166-
.dependsOn(
167-
"jsWorkerBrowserDistribution",
168-
"wasmWorkerBrowserDistribution",
169-
"wasmTestBrowserDistribution"
170-
)
171-
getByName("jsBrowserProductionWebpack")
172-
.dependsOn(
173-
"jsWorkerBrowserProductionWebpack",
174-
"wasmWorkerBrowserProductionWebpack",
175-
"wasmTestBrowserProductionWebpack"
176-
)
177-
getByName("jsBrowserDevelopmentWebpack")
178-
.dependsOn(
179-
"jsWorkerBrowserDevelopmentWebpack",
180-
"wasmWorkerBrowserDevelopmentWebpack",
181-
"wasmTestBrowserDevelopmentWebpack"
182-
)
183-
}
184-
185-
benchmark {
186-
configurations {
187-
register("findBestMove") {
188-
include(".*FindBestMoveBenchmark.*")
189-
}
190-
register("moveBoard") {
191-
include(".*MoveBoardBenchmark.*")
192-
}
193-
}
194-
}

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
org.gradle.jvmargs=-Xmx4g
22
kotlin.mpp.stability.nowarn=true
3+
org.gradle.warning.mode=none
4+
org.gradle.configuration-cache=true
5+
org.gradle.configuration-cache.problems=warn
6+
kotlin.mpp.applyDefaultHierarchyTemplate=false
37
kotlin.code.style=official
4-
allOpenVersion=1.8.21
5-
jmhVersion=1.36
6-
korgeVersion=4.0.9
7-
kotlinxBenchmarkVersion=0.4.7

gradle/libs.versions.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[plugins]
2+
korge = { id = "com.soywiz.korge", version = "6.0.0-beta4" }

gradle/wrapper/gradle-wrapper.jar

7.92 KB
Binary file not shown.
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
46
zipStoreBase=GRADLE_USER_HOME
5-
zipStorePath=wrapper/dists
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)