Skip to content

Commit

Permalink
Removed the original non-optimized version and updated the code for v…
Browse files Browse the repository at this point in the history
…ersion 1.19.8
  • Loading branch information
MothScientist committed Oct 31, 2024
1 parent caf5e3e commit 86ae9d2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 325 deletions.
67 changes: 28 additions & 39 deletions main_1.19.8_en/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

package main

import (
"fmt"
"math/rand"
"os"
"os/exec"
"golang.org/x/exp/slices" // crutch for versions before 1.21, since then the slices module is built-in
"sync"
"time"

"golang.org/x/exp/slices" // crutch for versions before 1.21, since then the slices module is built-in
)

type player struct {
Expand All @@ -20,7 +18,7 @@ type player struct {
}

func main() {
// Точка входа
// entry point

player_0 := player{
dice: [][]int{
Expand Down Expand Up @@ -68,42 +66,9 @@ func main() {
step = !step // pass the turn to another player

// we print the players' fields:
// TODO - выделить в отдельную функцию
fmt.Println(player_0.name)
for column := range player_0.dice {
for row := range player_0.dice[column] {
state := player_0.dice[row][column]
if state != 0 {
fmt.Print(state)
} else {
fmt.Print(" ")
}
fmt.Print(" ")
}
fmt.Print("\n")
}

fmt.Print("\n")
fmt.Printf("Score: %d", player_0.points)

printPlayerFields(&player_0)
fmt.Print("\n\n\n")

fmt.Println(player_1.name)
for column := range player_1.dice {
for row := range player_1.dice[column] {
state := player_1.dice[row][2-column] // "2 - column" it is necessary, since we output the matrix of the second player in the direction to the matrix of the first player
if state != 0 {
fmt.Print(state)
} else {
fmt.Print(" ")
}
fmt.Print(" ")
}
fmt.Print("\n")
}

fmt.Print("\n")
fmt.Printf("Score: %d", player_1.points)
printPlayerFields(&player_1)

// take the players' data depending on the move
if step {
Expand Down Expand Up @@ -284,3 +249,27 @@ func getUniqueElements[T comparable](arr []T) []T {
}
return uniq
}

func printPlayerFields(p *player) {
fmt.Println(p.name)
for column := range p.dice {
for row := range p.dice[column] {
var state int
if p.desk_position {
state = p.dice[row][2-column] // "2 - column" it is necessary, since we output the matrix of the second player in the direction to the matrix of the first player
} else {
state = p.dice[row][column]
}
if state != 0 {
fmt.Print(state)
} else {
fmt.Print(" ")
}
fmt.Print(" ")
}
fmt.Print("\n")
}

fmt.Print("\n")
fmt.Printf("Score: %d", p.points)
}
2 changes: 1 addition & 1 deletion main_1.22.5_en/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type player struct {
}

func main() {
// Точка входа
// entry point

player_0 := player{
dice: [][]int{
Expand Down
7 changes: 0 additions & 7 deletions main_ru/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions main_ru/go.sum

This file was deleted.

276 changes: 0 additions & 276 deletions main_ru/main.go

This file was deleted.

0 comments on commit 86ae9d2

Please sign in to comment.