banner
biuaxia

biuaxia

"万物皆有裂痕,那是光进来的地方。"
github
bilibili
tg_channel

Golang输出国际象棋

标题:Golang 输出国际象棋
日期:2022-05-18 15:33:00
目录:false
索引图片:https://b3logfile.com/file/2022/05/image-cdca4b06.png
分类:

  • Go
    标签:
  • Go
  • go
  • Golang
  • golang
  • 输出

package main

import (
	"fmt"
	"strings"
)

var (
	boardInfo = []string{
		"r", "k", "q", "r", "b", "n", "p", "r",
	}
)

func main() {
	var board [8][8]string
	for i := 0; i < len(boardInfo); i++ {
		board[0][i] = boardInfo[i]
	}
	for column := range board[len(board)-1] {
		board[len(board)-1][column] = strings.ToUpper(boardInfo[column])
	}

	for i := range board {
		for j := range board[i] {
			if board[i][j] == "" {
				board[i][j] = "·"
			}
		}
	}

	for i := 0; i < len(board); i++ {
		for j := 0; j < len(board[i]); j++ {
			fmt.Printf("%s\t", board[i][j])
		}
		fmt.Println()
	}
}

运行结果:

r       k       q       r       b       n       p       r
·       ·       ·       ·       ·       ·       ·       ·
·       ·       ·       ·       ·       ·       ·       ·
·       ·       ·       ·       ·       ·       ·       ·
·       ·       ·       ·       ·       ·       ·       ·
·       ·       ·       ·       ·       ·       ·       ·
·       ·       ·       ·       ·       ·       ·       ·
R       K       Q       R       B       N       P       R
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。