Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
Conway
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Adrian Kosmaczewski
Conway
Commits
82105a5f
Commit
82105a5f
authored
Oct 14, 2020
by
Adrian Kosmaczewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgraded Kotlin project to Android Studio 4.1
parent
9a02c1b0
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
103 additions
and
112 deletions
+103
-112
Kotlin/.idea/caches/build_file_checksums.ser
Kotlin/.idea/caches/build_file_checksums.ser
+0
-0
Kotlin/.idea/codeStyles/Project.xml
Kotlin/.idea/codeStyles/Project.xml
+3
-12
Kotlin/.idea/compiler.xml
Kotlin/.idea/compiler.xml
+6
-0
Kotlin/.idea/gradle.xml
Kotlin/.idea/gradle.xml
+1
-0
Kotlin/.idea/misc.xml
Kotlin/.idea/misc.xml
+1
-1
Kotlin/.idea/modules.xml
Kotlin/.idea/modules.xml
+2
-2
Kotlin/app/src/main/java/training/akosma/conway/MainActivity.kt
.../app/src/main/java/training/akosma/conway/MainActivity.kt
+9
-10
Kotlin/app/src/main/java/training/akosma/conway/World.kt
Kotlin/app/src/main/java/training/akosma/conway/World.kt
+52
-56
Kotlin/app/src/main/java/training/akosma/conway/WorldView.kt
Kotlin/app/src/main/java/training/akosma/conway/WorldView.kt
+26
-28
Kotlin/build.gradle
Kotlin/build.gradle
+1
-1
Kotlin/gradle/wrapper/gradle-wrapper.properties
Kotlin/gradle/wrapper/gradle-wrapper.properties
+2
-2
No files found.
Kotlin/.idea/caches/build_file_checksums.ser
View file @
82105a5f
No preview for this file type
Kotlin/.idea/codeStyles/Project.xml
View file @
82105a5f
...
...
@@ -3,18 +3,9 @@
<JetCodeStyleSettings>
<option
name=
"PACKAGES_TO_USE_STAR_IMPORTS"
>
<value>
<package
name=
"java.util"
alias=
"false"
withSubpackages=
"false"
/>
<package
name=
"kotlinx.android.synthetic"
alias=
"false"
withSubpackages=
"true"
/>
<package
name=
"io.ktor"
alias=
"false"
withSubpackages=
"true"
/>
</value>
</option>
<option
name=
"PACKAGES_IMPORT_LAYOUT"
>
<value>
<package
name=
""
alias=
"false"
withSubpackages=
"true"
/>
<package
name=
"java"
alias=
"false"
withSubpackages=
"true"
/>
<package
name=
"javax"
alias=
"false"
withSubpackages=
"true"
/>
<package
name=
"kotlin"
alias=
"false"
withSubpackages=
"true"
/>
<package
name=
""
alias=
"true"
withSubpackages=
"true"
/>
<package
name=
"java.util"
withSubpackages=
"false"
static=
"false"
/>
<package
name=
"kotlinx.android.synthetic"
withSubpackages=
"true"
static=
"false"
/>
<package
name=
"io.ktor"
withSubpackages=
"true"
static=
"false"
/>
</value>
</option>
<option
name=
"CODE_STYLE_DEFAULTS"
value=
"KOTLIN_OFFICIAL"
/>
...
...
Kotlin/.idea/compiler.xml
0 → 100644
View file @
82105a5f
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"CompilerConfiguration"
>
<bytecodeTargetLevel
target=
"1.8"
/>
</component>
</project>
\ No newline at end of file
Kotlin/.idea/gradle.xml
View file @
82105a5f
...
...
@@ -14,6 +14,7 @@
</set>
</option>
<option
name=
"resolveModulePerSourceSet"
value=
"false"
/>
<option
name=
"useQualifiedModuleNames"
value=
"true"
/>
</GradleProjectSettings>
</option>
</component>
...
...
Kotlin/.idea/misc.xml
View file @
82105a5f
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<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$/build/classes"
/>
</component>
<component
name=
"ProjectType"
>
...
...
Kotlin/.idea/modules.xml
View file @
82105a5f
...
...
@@ -2,8 +2,8 @@
<project
version=
"4"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/Conway.iml"
filepath=
"$PROJECT_DIR$/Conway.iml"
group=
"Conway"
/>
<module
fileurl=
"file://$PROJECT_DIR$/
app/app.iml"
filepath=
"$PROJECT_DIR$/app/app.iml"
group=
"Conway/app
"
/>
<module
fileurl=
"file://$PROJECT_DIR$/Conway.iml"
filepath=
"$PROJECT_DIR$/Conway.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/
.idea/modules/app/Conway.app.iml"
filepath=
"$PROJECT_DIR$/.idea/modules/app/Conway.app.iml
"
/>
</modules>
</component>
</project>
\ No newline at end of file
Kotlin/app/src/main/java/training/akosma/conway/MainActivity.kt
View file @
82105a5f
...
...
@@ -2,16 +2,16 @@ package training.akosma.conway
import
android.os.Bundle
import
android.os.Handler
import
android.os.Looper
import
androidx.appcompat.app.AppCompatActivity
class
MainActivity
:
AppCompatActivity
()
{
private
lateinit
var
world
:
World
private
lateinit
var
worldView
:
WorldView
private
val
handler
=
Handler
()
private
val
handler
=
Handler
(
Looper
.
getMainLooper
())
private
var
generation
:
Int
=
1
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
worldView
=
WorldView
(
this
)
val
alive
=
mutableListOf
<
Coord
>()
alive
.
addAll
(
World
.
blinker
(
Coord
(
0
,
1
)))
...
...
@@ -21,19 +21,18 @@ class MainActivity : AppCompatActivity() {
alive
.
addAll
(
World
.
block
(
Coord
(
18
,
3
)))
alive
.
addAll
(
World
.
tub
(
Coord
(
6
,
1
)))
world
=
World
(
30
,
alive
)
worldView
.
world
=
world
world
View
=
WorldView
(
this
)
worldView
.
world
=
World
(
30
,
alive
)
title
=
"Conway – Generation ${generation}"
setContentView
(
worldView
)
evolve
()
}
private
fun
evolve
()
{
val
runnable
=
Runnable
{
val
next
=
world
.
evolve
()
world
=
next
worldView
.
world
=
next
generation
+=
1
title
=
"Conway – Generation ${generation}"
worldView
.
world
=
worldView
.
world
.
evolve
()
evolve
()
}
handler
.
postDelayed
(
runnable
,
500
)
...
...
Kotlin/app/src/main/java/training/akosma/conway/World.kt
View file @
82105a5f
package
training.akosma.conway
class
World
(
val
size
:
Int
,
private
val
aliveCells
:
List
<
Coord
>
?
)
{
class
World
(
val
size
:
Int
,
private
val
aliveCells
:
List
<
Coord
>)
{
val
cells
=
mutableMapOf
<
Coord
,
Cell
>()
init
{
for
(
a
in
0
..
(
size
-
1
))
{
(
0
..
(
size
-
1
))
.
map
{
Coord
(
a
,
it
)
}
.
forEach
{
if
(
aliveCells
!=
null
&&
aliveCells
.
contains
(
it
))
{
cells
[
it
]
=
Cell
.
Alive
}
else
{
cells
[
it
]
=
Cell
.
Dead
}
for
(
a
in
0
until
size
)
{
(
0
until
size
)
.
map
{
Coord
(
a
,
it
)
}
.
forEach
{
if
(
aliveCells
.
contains
(
it
))
{
cells
[
it
]
=
Cell
.
Alive
}
else
{
cells
[
it
]
=
Cell
.
Dead
}
}
}
}
fun
evolve
():
World
{
val
alive
=
mutableListOf
<
Coord
>()
for
((
coord
,
cell
)
in
cells
)
{
var
count
=
0
(-
1
..
1
).
map
{
a
->
count
+=
(-
1
..
1
)
.
map
{
Coord
(
coord
.
x
+
a
,
coord
.
y
+
it
)
}
.
filter
{
it
!=
coord
}
.
map
{
cells
[
it
]
}
.
count
{
it
==
Cell
.
Alive
}
.
map
{
Coord
(
coord
.
x
+
a
,
coord
.
y
+
it
)
}
.
filter
{
it
!=
coord
}
.
map
{
cells
[
it
]
}
.
count
{
it
==
Cell
.
Alive
}
}
when
(
cell
)
{
...
...
@@ -43,37 +42,34 @@ class World(val size: Int, private val aliveCells: List<Coord>?) {
}
}
}
return
World
(
size
,
alive
)
}
override
fun
toString
():
String
{
var
str
=
""
for
(
a
in
0
..
(
size
-
1
))
{
val
str
=
StringBuffer
()
for
(
a
in
0
until
size
)
{
if
(
a
==
0
)
{
// First line with coordinates
str
+=
" "
for
(
b
in
0
..
(
size
-
1
)
)
{
str
+=
String
.
format
(
"%1$3s|"
,
b
)
str
.
append
(
" "
)
for
(
b
in
0
until
size
)
{
str
.
append
(
String
.
format
(
"%1$3s|"
,
b
)
)
}
str
+=
"\n"
str
.
append
(
"\n"
)
}
str
+=
String
.
format
(
"%1$3s|"
,
a
)
str
+=
(
0
..
(
size
-
1
)
)
.
map
{
Coord
(
it
,
a
)
}
.
map
{
cells
[
it
]
?.
tableDescription
()
}
.
reduce
{
acc
,
s
->
acc
+
s
}
str
+=
"\n"
str
.
append
(
String
.
format
(
"%1$3s|"
,
a
)
)
str
.
append
((
0
until
size
)
.
map
{
Coord
(
it
,
a
)
}
.
map
{
cells
[
it
]
?.
tableDescription
()
}
.
reduce
{
acc
,
s
->
acc
+
s
})
str
.
append
(
"\n"
)
}
return
str
return
str
.
toString
()
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
if
(
this
===
other
)
return
true
if
(
other
is
World
)
{
return
cells
==
other
.
cells
return
cells
==
other
.
cells
&&
size
==
other
.
size
}
return
false
}
...
...
@@ -85,50 +81,50 @@ class World(val size: Int, private val aliveCells: List<Coord>?) {
companion
object
{
fun
blinker
(
coord
:
Coord
):
List
<
Coord
>
{
return
listOf
(
Coord
(
coord
.
x
,
coord
.
y
),
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
+
2
,
coord
.
y
)
Coord
(
coord
.
x
,
coord
.
y
),
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
+
2
,
coord
.
y
)
)
}
fun
beacon
(
coord
:
Coord
):
List
<
Coord
>
{
return
listOf
(
Coord
(
coord
.
x
,
coord
.
y
),
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
3
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
3
),
Coord
(
coord
.
x
+
3
,
coord
.
y
+
3
)
Coord
(
coord
.
x
,
coord
.
y
),
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
3
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
3
),
Coord
(
coord
.
x
+
3
,
coord
.
y
+
3
)
)
}
fun
glider
(
coord
:
Coord
):
List
<
Coord
>
{
return
listOf
(
Coord
(
coord
.
x
+
2
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
2
),
Coord
(
coord
.
x
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
)
Coord
(
coord
.
x
+
2
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
2
),
Coord
(
coord
.
x
,
coord
.
y
+
2
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
)
)
}
fun
block
(
coord
:
Coord
):
List
<
Coord
>
{
return
listOf
(
Coord
(
coord
.
x
,
coord
.
y
),
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
1
)
Coord
(
coord
.
x
,
coord
.
y
),
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
1
)
)
}
fun
tub
(
coord
:
Coord
):
List
<
Coord
>
{
return
listOf
(
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
2
)
Coord
(
coord
.
x
+
1
,
coord
.
y
),
Coord
(
coord
.
x
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
2
,
coord
.
y
+
1
),
Coord
(
coord
.
x
+
1
,
coord
.
y
+
2
)
)
}
}
...
...
Kotlin/app/src/main/java/training/akosma/conway/WorldView.kt
View file @
82105a5f
...
...
@@ -5,7 +5,7 @@ import android.graphics.*
import
android.view.View
class
WorldView
(
context
:
Context
)
:
View
(
context
)
{
private
var
mWorld
:
World
?
=
null
private
lateinit
var
mWorld
:
World
private
var
mRectangles
=
mutableMapOf
<
Coord
,
Rect
>()
private
var
mPaths
=
mutableListOf
<
Path
>()
...
...
@@ -31,7 +31,7 @@ class WorldView(context: Context) : View(context) {
}
}
var
world
:
World
?
var
world
:
World
get
()
=
mWorld
set
(
newWorld
)
{
mWorld
=
newWorld
...
...
@@ -41,39 +41,37 @@ class WorldView(context: Context) : View(context) {
override
fun
onDraw
(
canvas
:
Canvas
)
{
super
.
onDraw
(
canvas
)
if
(
mWorld
!=
null
)
{
val
world
=
mWorld
!!
val
size
=
world
.
size
val
contentWidth
=
width
val
contentHeight
=
height
val
world
=
mWorld
val
size
=
world
.
size
val
contentWidth
=
width
val
contentHeight
=
height
val
horizontalStep
=
contentWidth
/
size
val
verticalStep
=
contentHeight
/
size
val
horizontalStep
=
contentWidth
/
size
val
verticalStep
=
contentHeight
/
size
if
(
mRectangles
.
count
()
==
0
)
{
createRectangles
(
horizontalStep
,
verticalStep
)
}
for
((
coord
,
cell
)
in
world
.
cells
)
{
if
(
cell
==
Cell
.
Alive
)
{
val
rect
=
mRectangles
[
coord
]
if
(
rect
!=
null
)
{
canvas
.
drawRect
(
rect
,
cellPaint
)
canvas
.
drawRect
(
rect
,
cellStroke
)
}
if
(
mRectangles
.
count
()
==
0
)
{
createRectangles
(
horizontalStep
,
verticalStep
)
}
for
((
coord
,
cell
)
in
world
.
cells
)
{
if
(
cell
==
Cell
.
Alive
)
{
val
rect
=
mRectangles
[
coord
]
if
(
rect
!=
null
)
{
canvas
.
drawRect
(
rect
,
cellPaint
)
canvas
.
drawRect
(
rect
,
cellStroke
)
}
}
}
if
(
mPaths
.
count
()
==
0
)
{
createGrid
(
horizontalStep
,
verticalStep
,
contentWidth
,
contentHeight
)
}
for
(
path
in
mPaths
)
{
canvas
.
drawPath
(
path
,
linePaint
)
}
if
(
mPaths
.
count
()
==
0
)
{
createGrid
(
horizontalStep
,
verticalStep
,
contentWidth
,
contentHeight
)
}
for
(
path
in
mPaths
)
{
canvas
.
drawPath
(
path
,
linePaint
)
}
}
private
fun
createRectangles
(
horizontalStep
:
Int
,
verticalStep
:
Int
)
{
for
((
coord
,
_
)
in
mWorld
!!
.
cells
)
{
for
((
coord
,
_
)
in
mWorld
.
cells
)
{
val
x
=
coord
.
x
*
horizontalStep
val
y
=
coord
.
y
*
verticalStep
val
rect
=
Rect
(
x
,
y
,
x
+
horizontalStep
,
y
+
verticalStep
)
...
...
@@ -83,7 +81,7 @@ class WorldView(context: Context) : View(context) {
private
fun
createGrid
(
horizontalStep
:
Int
,
verticalStep
:
Int
,
contentWidth
:
Int
,
contentHeight
:
Int
)
{
// Vertical lines
for
(
i
in
1
..
(
mWorld
!!
.
size
-
1
)
)
{
for
(
i
in
1
until
mWorld
.
size
)
{
val
vertical
=
Path
()
val
distance
=
i
.
toFloat
()
vertical
.
moveTo
(
horizontalStep
*
distance
,
0f
)
...
...
@@ -92,7 +90,7 @@ class WorldView(context: Context) : View(context) {
}
// Horizontal lines
for
(
j
in
1
..
(
mWorld
!!
.
size
-
1
)
)
{
for
(
j
in
1
until
mWorld
.
size
)
{
val
horizontal
=
Path
()
val
distance
=
j
.
toFloat
()
horizontal
.
moveTo
(
0f
,
verticalStep
*
distance
)
...
...
Kotlin/build.gradle
View file @
82105a5f
...
...
@@ -8,7 +8,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:4.
0.1
'
classpath
'com.android.tools.build:gradle:4.
1.0
'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
...
...
Kotlin/gradle/wrapper/gradle-wrapper.properties
View file @
82105a5f
#
Sat Oct 03 13:43:29
CEST 2020
#
Wed Oct 14 16:53:15
CEST 2020
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-6.
1.1-all
.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-6.
5-bin
.zip
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment